|
| 1 | +.. _pymongo-motor-to-async: |
| 2 | + |
| 3 | +=================================== |
| 4 | +Migrate from Motor to {+driver-async+} |
| 5 | +=================================== |
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 1 |
| 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+} is a unification of {+driver-short+} and the Motor library. |
| 24 | +In this guide, you can identify the changes you must make to migrate an |
| 25 | +application from Motor to {+driver-async+}. |
| 26 | + |
| 27 | +Prerequisites |
| 28 | +------------- |
| 29 | + |
| 30 | +To migrate from Motor to {+driver-async+}, you must first complete the following |
| 31 | +steps: |
| 32 | + |
| 33 | +1. Upgrade Motor to v3.6. |
| 34 | +#. Run your application to identify any warnings or errors. |
| 35 | +#. Update your application to remove all warnings and errors. |
| 36 | +#. Update any imports in your application that import from the ``motor`` library |
| 37 | + to instead import from ``pymongo.asynchronous``. |
| 38 | + |
| 39 | +API Changes |
| 40 | +----------- |
| 41 | + |
| 42 | +To use the following collection method calls, you must wrap them in an ``await`` |
| 43 | +statement: |
| 44 | + |
| 45 | +- ``aggregate()`` |
| 46 | +- ``aggregate_raw_batches()`` |
| 47 | +- ``watch()`` |
| 48 | +- ``list_indexes()`` |
| 49 | +- ``list_search_indexes()`` |
| 50 | + |
| 51 | +The following example demonstrates how to call the ``list_search_indexes()`` method with |
| 52 | +{+driver-async+}: |
| 53 | + |
| 54 | +.. code-block:: python |
| 55 | + |
| 56 | + results = await collection.list_search_indexes() |
| 57 | + |
| 58 | +The following methods are not asynchronous in {+driver-async+}: |
| 59 | + |
| 60 | +- ``MongoClient.start_session()`` |
| 61 | + |
| 62 | +The following methods are asynchronous in {+driver-async+}: |
| 63 | + |
| 64 | +- ``AsyncClientSession.start_transaction()`` |
| 65 | +- ``Cursor.rewind()`` |
| 66 | + |
| 67 | +Method Signature Changes |
| 68 | +------------------------ |
| 69 | + |
| 70 | +The following method signatures are changed in {+driver-async+}: |
| 71 | + |
| 72 | +- ``GridOut.open()`` now returns ``None``. |
| 73 | +- ``AsyncMongoClient.__init__`` no longer accepts an ``io_loop`` parameter. |
| 74 | +- ``Gridln.set()`` does not accept a filename. Instead pass a file name by using the |
| 75 | + ``Gridln.filename`` attribute. |
| 76 | +- ``Cursor.each()`` is removed. |
| 77 | +- ``to_list(0)`` is no longer valid. Use ``to_list(None)`` instead. |
0 commit comments