1
- .. _pymongo-async-migration :
1
+ .. _pymongo-to- async-guide :
2
2
3
- ===================================
4
- Migrate to the {+driver-async+} Driver
5
- ===================================
3
+ ====================================
4
+ Switch from {+driver-short+} to {+driver-async+}
5
+ ====================================
6
6
7
7
.. contents:: On this page
8
8
:local:
@@ -15,15 +15,15 @@ Migrate to the {+driver-async+} Driver
15
15
:values: reference
16
16
17
17
.. meta::
18
- :keywords: motor, async , refactor, migration
18
+ :keywords: asyncronous , refactor, migration
19
19
20
20
Overview
21
21
--------
22
22
23
23
The {+driver-async+} driver is a unification of {+driver-short+} and the `Motor
24
24
library <https://www.mongodb.com/docs/drivers/motor/>`__. In this guide, you can
25
- identify the changes you must make to migrate an application from
26
- {+driver-short+} or Motor to the {+driver- async+} driver .
25
+ identify the changes you must make to switch from {+driver-short+} to
26
+ {+driver-async+}.
27
27
28
28
Migrate From {+driver-short+}
29
29
--------------------
@@ -39,6 +39,8 @@ in the following ways:
39
39
40
40
The following sections describe how to implement the asynchronous API.
41
41
42
+ .. _pymongo-async-methods:
43
+
42
44
Asynchronous Methods
43
45
~~~~~~~~~~~~~~~~~~~~
44
46
@@ -61,7 +63,7 @@ Client Methods
61
63
62
64
from pymongo import AsyncMongoClient
63
65
64
- AsyncMongoClient(...)
66
+ async with AsyncMongoClient(...)
65
67
66
68
* - ``watch()``
67
69
- .. code-block:: python
@@ -319,39 +321,8 @@ Collection Methods
319
321
320
322
await collection.find_one_and_update(...)
321
323
322
- Migrate From Motor
323
- ------------------
324
-
325
- The {+driver-async+} driver behaves nearly identically to the Motor library. In
326
- most cases, you can directly migrate existing Motor applications to
327
- {+driver-async+} by using ``AsyncMongoClient`` in place of ``MotorClient``, and
328
- changing the application's import statements to import from ``pymongo``.
329
-
330
- The following example shows the difference in imports to use a client for
331
- read and write operations in Motor compared to {+driver-async+}:
332
-
333
- .. code-block:: python
334
-
335
- # Motor client import
336
- from motor.motor_asyncio import AsyncIOMotorClient
337
-
338
- # {+driver-async+} client import
339
- from pymongo import AsyncMongoClient
340
-
341
-
342
- The following section shows the method signature changes that you must implement
343
- in your application when migrating from Motor to the {+driver-async+} driver.
344
-
345
- Method Signature Changes
346
- ~~~~~~~~~~~~~~~~~~~~~~~~
347
-
348
- The following Motor method signatures behave differently in the {+driver-async+} driver:
324
+ Additional Information
325
+ ----------------------
349
326
350
- - ``GridOut.open()`` returns ``None``.
351
- - ``AsyncMongoClient.__init__()`` does not accept an ``io_loop`` parameter.
352
- - ``GridIn.set()`` does not accept a filename. Instead pass a file name by using the
353
- ``GridIn.filename`` attribute.
354
- - ``Cursor.each()`` does not exist in the {+driver-async+} driver.
355
- - ``stream_to_handler()`` does not exist in the {+driver-async+} driver.
356
- - ``to_list(0)`` is not valid in the {+driver-async+} driver. Use
357
- ``to_list(None)`` instead.
327
+ To learn more about asynchronous Python, see the `Python Asyncio documentation
328
+ <https://docs.python.org/3/library/asyncio.html>`__.
0 commit comments