-
Notifications
You must be signed in to change notification settings - Fork 20
DOCSP-41887 Async Migration Guide #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
c29250e
7a49198
5e2d5a5
ca264a9
e36034b
bc1a8a3
3e9acc3
edfff73
3045f0d
6f728ce
301ba14
6637b87
102c829
afc9ddf
bf38a06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
.. _pymongo-async-motor-migration: | ||
|
||
==================================== | ||
Migrate from Motor to {+driver-async+} | ||
==================================== | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 2 | ||
:class: singlecol | ||
|
||
.. facet:: | ||
:name: genre | ||
:values: reference | ||
|
||
.. meta:: | ||
:keywords: motor, async, refactor, migration | ||
|
||
Overview | ||
-------- | ||
|
||
The {+driver-async+} driver is a unification of {+driver-short+} and the `Motor | ||
library <https://www.mongodb.com/docs/drivers/motor/>`__. In this guide, you can | ||
identify the changes you must make to migrate an application from | ||
Motor to the {+driver-async+} driver. | ||
|
||
Migrate From Motor | ||
------------------ | ||
|
||
The {+driver-async+} driver functions similarly to the Motor library, but allows | ||
for improved latency and throughput due to directly using Python Asyncio instead | ||
of delegating work to a thread pool. In most cases, you can directly migrate | ||
existing Motor applications to {+driver-async+} by using ``AsyncMongoClient`` in | ||
place of ``MotorClient``, and changing the application's import statements to | ||
import from ``pymongo``. | ||
|
||
The following example shows the difference in imports to use a client for | ||
read and write operations in Motor compared to {+driver-async+}: | ||
|
||
.. code-block:: python | ||
|
||
# Motor client import | ||
from motor.motor_asyncio import AsyncIOMotorClient | ||
|
||
# {+driver-async+} client import | ||
from pymongo import AsyncMongoClient | ||
|
||
To see a list of the asynchronous methods available in the {+driver-async+} | ||
driver, see the :ref:`pymongo-async-methods` section in the {+driver-short+} to | ||
{+driver-async+} guide. | ||
|
||
The following section shows the method signature changes that you must implement | ||
in your application when migrating from Motor to the {+driver-async+} driver. | ||
|
||
Method Signature Changes | ||
~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The following Motor method signatures behave differently in the {+driver-async+} driver: | ||
|
||
- ``GridOut.open()`` returns ``None``. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does |
||
- ``AsyncMongoClient.__init__()`` does not accept an ``io_loop`` parameter. | ||
- ``GridIn.set()`` does not accept a filename. Instead pass a file name by using the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @noah is this true? Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These were from the original draft migration notes linked in the ticket. Should I delete the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
``GridIn.filename`` attribute. | ||
- ``Cursor.each()`` does not exist in the {+driver-async+} driver. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cursor -> AsyncCursor. |
||
- ``stream_to_handler()`` does not exist in the {+driver-async+} driver. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
- ``to_list(0)`` is not valid in the {+driver-async+} driver. Use | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
``to_list(None)`` instead. | ||
|
||
Additional Information | ||
---------------------- | ||
|
||
To learn more about asynchronous Python, see the `Python Asyncio documentation | ||
<https://docs.python.org/3/library/asyncio.html>`__. |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Async PyMongo is released yes, but it's only in beta (ie experimental) and not ready for production use. We should make this loud and clear one every one of these pages.