@@ -33,7 +33,7 @@ all methods that perform network operations are coroutines and must be awaited.
33
33
To migrate from {+driver-short+} to {+driver-async+}, you must update your code
34
34
to replace all uses of ``MongoClient`` with ``AsyncMongoClient`` and add the
35
35
``await`` keyword to all asynchronous method calls. If an asynchronous method is
36
- called within a function, you must mark the function as ``async``.
36
+ called within a function, you must also mark the function as ``async``.
37
37
38
38
Asynchronous Methods
39
39
~~~~~~~~~~~~~~~~~~~~
@@ -52,35 +52,35 @@ Client Methods
52
52
53
53
* - ``AsyncMongoClient()``
54
54
- .. code-block:: python
55
-
55
+
56
56
from pymongo import AsyncMongoClient
57
57
58
58
client = AsyncMongoClient(...)
59
59
60
60
* - ``watch()``
61
61
- .. code-block:: python
62
-
62
+
63
63
async with await client.watch(...) as stream:
64
64
...
65
65
66
66
* - ``server_info()``
67
67
- .. code-block:: python
68
-
68
+
69
69
info = await client.server_info(...)
70
70
71
71
* - ``list_databases()``
72
72
- .. code-block:: python
73
-
73
+
74
74
databases = await client.list_databases()
75
75
76
76
* - ``list_database_names()``
77
77
- .. code-block:: python
78
-
78
+
79
79
database_names = await client.list_database_names()
80
80
81
81
* - ``drop_database()``
82
82
- .. code-block:: python
83
-
83
+
84
84
await client.drop_database(...)
85
85
86
86
Database Methods
@@ -95,13 +95,13 @@ Database Methods
95
95
96
96
* - ``watch()``
97
97
- .. code-block:: python
98
-
98
+
99
99
async with await db.watch(...) as stream:
100
- ...
100
+ ...
101
101
102
102
* - ``create_collection()``
103
103
- .. code-block:: python
104
-
104
+
105
105
await db.create_collection(...)
106
106
107
107
* - ``aggregate()``
@@ -112,7 +112,7 @@ Database Methods
112
112
113
113
* - ``command()``
114
114
- .. code-block:: python
115
-
115
+
116
116
result = await db.command(...)
117
117
118
118
* - ``cursor_command()``
@@ -122,27 +122,27 @@ Database Methods
122
122
123
123
* - ``list_collections()``
124
124
- .. code-block:: python
125
-
125
+
126
126
collections = await db.list_collections()
127
127
128
128
* - ``list_collection_names()``
129
129
- .. code-block:: python
130
-
130
+
131
131
collection_names = await db.list_collection_names()
132
132
133
133
* - ``drop_collection()``
134
134
- .. code-block:: python
135
-
135
+
136
136
await db.drop_collection(...)
137
-
137
+
138
138
* - ``validate_collection()``
139
139
- .. code-block:: python
140
-
140
+
141
141
result = await db.validate_collection(...)
142
142
143
143
* - ``dereference()``
144
144
- .. code-block:: python
145
-
145
+
146
146
result = await db.dereference(...)
147
147
148
148
Collection Methods
@@ -157,48 +157,48 @@ Collection Methods
157
157
158
158
* - ``watch()``
159
159
- .. code-block:: python
160
-
160
+
161
161
async with await collection.watch(...) as stream:
162
- ...
162
+ ...
163
163
164
164
* - ``insert_one()``
165
165
- .. code-block:: python
166
-
166
+
167
167
await collection.insert_one(...)
168
168
169
169
* - ``insert_many()``
170
170
- .. code-block:: python
171
-
171
+
172
172
await collection.insert_many(...)
173
-
173
+
174
174
* - ``replace_one()``
175
175
- .. code-block:: python
176
-
176
+
177
177
await collection.replace_one(...)
178
178
179
179
* - ``update_one()``
180
180
- .. code-block:: python
181
-
181
+
182
182
await collection.update_one(...)
183
183
184
184
* - ``update_many()``
185
185
- .. code-block:: python
186
-
186
+
187
187
await collection.update_many(...)
188
188
189
189
* - ``drop()``
190
190
- .. code-block:: python
191
-
191
+
192
192
await collection.drop()
193
193
194
194
* - ``delete_one()``
195
195
- .. code-block:: python
196
-
196
+
197
197
await collection.delete_one(...)
198
198
199
199
* - ``delete_many()``
200
200
- .. code-block:: python
201
-
201
+
202
202
await collection.delete_many(...)
203
203
204
204
* - ``find_one()``
@@ -208,12 +208,12 @@ Collection Methods
208
208
209
209
* - ``estimated_document_count()``
210
210
- .. code-block:: python
211
-
211
+
212
212
count = await collection.estimated_document_count()
213
213
214
214
* - ``count_documents()``
215
215
- .. code-block:: python
216
-
216
+
217
217
count = await collection.count_documents(...)
218
218
219
219
* - ``create_index()``
@@ -228,89 +228,89 @@ Collection Methods
228
228
229
229
* - ``drop_index()``
230
230
- .. code-block:: python
231
-
231
+
232
232
await collection.drop_index(...)
233
233
234
234
* - ``drop_indexes()``
235
235
- .. code-block:: python
236
-
236
+
237
237
await collection.drop_indexes()
238
238
239
239
* - ``list_indexes()``
240
240
- .. code-block:: python
241
-
241
+
242
242
indexes = await collection.list_indexes()
243
243
244
244
* - ``index_information()``
245
245
- .. code-block:: python
246
-
246
+
247
247
info = await collection.index_information()
248
248
249
249
* - ``list_search_indexes()``
250
250
- .. code-block:: python
251
-
251
+
252
252
indexes = await collection.list_search_indexes()
253
253
254
254
* - ``create_search_index()``
255
255
- .. code-block:: python
256
-
256
+
257
257
await collection.create_search_index(...)
258
258
259
259
* - ``create_search_indexes()``
260
260
- .. code-block:: python
261
-
261
+
262
262
await collection.create_search_indexes(...)
263
263
264
264
* - ``drop_search_index()``
265
265
- .. code-block:: python
266
-
266
+
267
267
await collection.drop_search_index(...)
268
268
269
269
* - ``update_search_index()``
270
270
- .. code-block:: python
271
-
271
+
272
272
await collection.update_search_index(...)
273
273
274
274
* - ``options()``
275
275
- .. code-block:: python
276
-
276
+
277
277
options = await collection.options()
278
278
279
279
* - ``aggregate()``
280
280
- .. code-block:: python
281
-
281
+
282
282
async for doc in await collection.aggregate(...):
283
283
...
284
284
285
285
* - ``aggregate_raw_batches()``
286
286
- .. code-block:: python
287
-
287
+
288
288
async for batch in await collection.aggregate_raw_batches(...):
289
289
...
290
290
291
291
* - ``rename()``
292
292
- .. code-block:: python
293
-
293
+
294
294
await collection.rename(...)
295
295
296
296
* - ``distinct()``
297
297
- .. code-block:: python
298
-
298
+
299
299
distinct_values = await collection.distinct(...)
300
300
301
301
* - ``find_one_and_delete()``
302
302
- .. code-block:: python
303
-
303
+
304
304
result = await collection.find_one_and_delete(...)
305
305
306
306
* - ``find_one_and_replace()``
307
307
- .. code-block:: python
308
-
308
+
309
309
result = await collection.find_one_and_replace(...)
310
310
311
311
* - ``find_one_and_update()``
312
312
- .. code-block:: python
313
-
313
+
314
314
result = await collection.find_one_and_update(...)
315
315
316
316
Migrate From Motor
0 commit comments