Skip to content

Commit e36034b

Browse files
Rea feedback
1 parent ca264a9 commit e36034b

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

source/pymongo-async-migration.txt

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,32 @@ Migrate to the {+driver-async+} Driver
2020
Overview
2121
--------
2222

23-
The {+driver-async+} driver is a unification of {+driver-short+} and the `Motor
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.
23+
In September 2024, MongoDB released the {+driver-async+} driver to unify {+driver-short+}
24+
and `Motor <https://www.mongodb.com/docs/drivers/motor/>`__, the asynchronous
25+
MongoDB driver for Python. In this guide, you can identify the changes you must
26+
make to migrate an application from {+driver-short+} or Motor to the
27+
{+driver-async+} driver.
2728

2829
Migrate From {+driver-short+}
2930
--------------------
3031

3132
The {+driver-async+} driver behaves similarly to {+driver-short+}, but
3233
all methods that perform network operations are coroutines and must be awaited.
3334
To migrate from {+driver-short+} to {+driver-async+}, you must update your code
34-
to replace all uses of ``MongoClient`` with ``AsyncMongoClient`` and add the
35-
``await`` keyword to all asynchronous method calls. If an asynchronous method is
36-
called within a function, you must also mark the function as ``async``.
35+
in the following ways:
36+
37+
- Replace all uses of ``MongoClient`` with ``AsyncMongoClient``.
38+
- Add the ``await`` keyword to all asynchronous method calls .
39+
- If an asynchronous method is called within a function, mark the function as ``async``.
40+
41+
The following sections describe how to implement the asynchronous API.
3742

3843
Asynchronous Methods
3944
~~~~~~~~~~~~~~~~~~~~
4045

41-
The following methods are asynchronous in {+driver-async+}:
46+
The following tables list the asynchronous methods that are available in the
47+
{+driver-async+} driver. To call these methods, you must ``await`` them and call them
48+
inside an ``async`` function.
4249

4350
Client Methods
4451
``````````````
@@ -318,8 +325,20 @@ Migrate From Motor
318325

319326
The {+driver-async+} driver behaves nearly identically to the Motor library. In
320327
most cases, you can directly migrate existing Motor applications to
321-
{+driver-short+}, changing only the application's import statements, and
322-
by using ``AsyncMongoClient`` in place of ``MotorClient``.
328+
{+driver-short+ by using ``AsyncMongoClient`` in place of ``MotorClient``, and
329+
changing the application's import statements to import from ``pymongo``.
330+
331+
The following example shows the difference in imports to use a client for
332+
read and write operations in Motor compared to {+driver-async+}:
333+
334+
.. code-block:: python
335+
336+
# Motor client import
337+
from motor.motor_asyncio import AsyncIOMotorClient
338+
339+
# {+driver-async+} client import
340+
from pymongo import AsyncMongoClient
341+
323342

324343
The following section shows the method signature changes that you must make when
325344
migrating from Motor to the {+driver-async+} driver:
@@ -336,4 +355,4 @@ The following Motor method signatures behave differently in the {+driver-async+}
336355
- ``Cursor.each()`` does not exist in the {+driver-async+} driver.
337356
- ``stream_to_handler()`` does not exist in the {+driver-async+} driver.
338357
- ``to_list(0)`` is not valid in the {+driver-async+} driver. Use
339-
``to_list(None)`` instead.
358+
``to_list(None)`` instead.

0 commit comments

Comments
 (0)