Skip to content

Commit 6f728ce

Browse files
split into two pages + feedback
1 parent 3045f0d commit 6f728ce

File tree

3 files changed

+103
-50
lines changed

3 files changed

+103
-50
lines changed

source/index.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ MongoDB {+driver-short+} Documentation
2626
/troubleshooting
2727
/whats-new
2828
/upgrade
29-
/pymongo-async-migration
29+
/pymongo-async-motor-migration
30+
/pymongo-to-async-guide
3031
/previous-versions
3132
/issues-and-help
3233
/compatibility
@@ -121,13 +122,20 @@ Upgrade {+driver-short+} Versions
121122
Learn what changes you might need to make to your application to upgrade driver versions
122123
in the :ref:`pymongo-upgrade` section.
123124

124-
Migrate to the {+driver-async+} Driver
125-
------------------------------------
125+
Migrate from Motor to the {+driver-async+} Driver
126+
------------------------------------------------
127+
128+
In September 2024, MongoDB released the {+driver-async+} driver as a replacement
129+
for `Motor <https://www.mongodb.com/docs/drivers/motor/>`__, the previous asynchronous
130+
MongoDB driver for Python. Learn how to migrate from Motor
131+
to the {+driver-async+} driver in the :ref:`pymongo-async-motor-migration`
132+
section.
133+
134+
Switch from {+driver-short+} to {+driver-async+}
135+
----------------------------------------------
126136

127-
In September 2024, MongoDB released the {+driver-async+} driver to unify {+driver-short+}
128-
and `Motor <https://www.mongodb.com/docs/drivers/motor/>`__, the asynchronous
129-
MongoDB driver for Python. Learn how to migrate from {+driver-short+} or Motor
130-
to the {+driver-async+} driver in the :ref:`pymongo-async-migration` section.
137+
Learn what changes you need to make to switch from {+driver-short+} to
138+
{+driver-async+} in the :ref:`pymongo-to-async-guide` section.
131139

132140
Previous Versions
133141
-----------------

source/motor-async-migration.txt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
.. _pymongo-async-motor-migration:
2+
3+
===============================================
4+
Migrate from Motor to the {+driver-async+} Driver
5+
===============================================
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
.. facet::
14+
:name: genre
15+
:values: reference
16+
17+
.. meta::
18+
:keywords: motor, async, refactor, migration
19+
20+
Overview
21+
--------
22+
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.
27+
28+
Migrate From Motor
29+
------------------
30+
31+
The {+driver-async+} driver functions similarly to the Motor library, but allows
32+
for improved latency and throughput due to directly using Python Asyncio instead
33+
of delegating work to a thread pool. In most cases, you can directly migrate
34+
existing Motor applications to {+driver-async+} by using ``AsyncMongoClient`` in
35+
place of ``MotorClient``, and changing the application's import statements to
36+
import from ``pymongo``.
37+
38+
The following example shows the difference in imports to use a client for
39+
read and write operations in Motor compared to {+driver-async+}:
40+
41+
.. code-block:: python
42+
43+
# Motor client import
44+
from motor.motor_asyncio import AsyncIOMotorClient
45+
46+
# {+driver-async+} client import
47+
from pymongo import AsyncMongoClient
48+
49+
To see a list of the asynchronous methods available in the {+driver-async+}
50+
driver, see the :ref:`pymongo-async-methods` section in the {+driver-short+} to
51+
{+driver-async+} guide.
52+
53+
The following section shows the method signature changes that you must implement
54+
in your application when migrating from Motor to the {+driver-async+} driver.
55+
56+
Method Signature Changes
57+
~~~~~~~~~~~~~~~~~~~~~~~~
58+
59+
The following Motor method signatures behave differently in the {+driver-async+} driver:
60+
61+
- ``GridOut.open()`` returns ``None``.
62+
- ``AsyncMongoClient.__init__()`` does not accept an ``io_loop`` parameter.
63+
- ``GridIn.set()`` does not accept a filename. Instead pass a file name by using the
64+
``GridIn.filename`` attribute.
65+
- ``Cursor.each()`` does not exist in the {+driver-async+} driver.
66+
- ``stream_to_handler()`` does not exist in the {+driver-async+} driver.
67+
- ``to_list(0)`` is not valid in the {+driver-async+} driver. Use
68+
``to_list(None)`` instead.
69+
70+
Additional Information
71+
----------------------
72+
73+
To learn more about asynchronous Python, see the `Python Asyncio documentation
74+
<https://docs.python.org/3/library/asyncio.html>`__.

source/pymongo-async-migration.txt renamed to source/pymongo-to-async-guide.txt

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
.. _pymongo-async-migration:
1+
.. _pymongo-to-async-guide:
22

3-
===================================
4-
Migrate to the {+driver-async+} Driver
5-
===================================
3+
====================================
4+
Switch from {+driver-short+} to {+driver-async+}
5+
====================================
66

77
.. contents:: On this page
88
:local:
@@ -15,15 +15,15 @@ Migrate to the {+driver-async+} Driver
1515
:values: reference
1616

1717
.. meta::
18-
:keywords: motor, async, refactor, migration
18+
:keywords: asyncronous, refactor, migration
1919

2020
Overview
2121
--------
2222

2323
The {+driver-async+} driver is a unification of {+driver-short+} and the `Motor
2424
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+}.
2727

2828
Migrate From {+driver-short+}
2929
--------------------
@@ -39,6 +39,8 @@ in the following ways:
3939

4040
The following sections describe how to implement the asynchronous API.
4141

42+
.. _pymongo-async-methods:
43+
4244
Asynchronous Methods
4345
~~~~~~~~~~~~~~~~~~~~
4446

@@ -61,7 +63,7 @@ Client Methods
6163

6264
from pymongo import AsyncMongoClient
6365

64-
AsyncMongoClient(...)
66+
async with AsyncMongoClient(...)
6567

6668
* - ``watch()``
6769
- .. code-block:: python
@@ -319,39 +321,8 @@ Collection Methods
319321

320322
await collection.find_one_and_update(...)
321323

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+
----------------------
349326

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

Comments
 (0)