@@ -17,49 +17,117 @@ Motor (Async Driver)
1717Introduction
1818------------
1919
20- **Motor (Python async)** is the recommended asynchronous Python driver for MongoDB.
21- It is compatible with `Tornado <http://www.tornadoweb.org/>`_ and
22- `asyncio <https://docs.python.org/3/library/asyncio.html>`_.
20+ **Motor** is the recommended asynchronous Python driver for MongoDB.
21+ It is compatible with `Tornado <http://www.tornadoweb.org/>`__ and
22+ `asyncio <https://docs.python.org/3/library/asyncio.html>`__. We recommend
23+ that you use this driver if you need to run asynchronous operations. If
24+ you do not need to access MongoDB in a non-blocking manner or from
25+ co-routines, we recommend that you use the :doc:`PyMongo </pymongo>`
26+ driver instead.
2327
24- - `Tutorial <http://motor.readthedocs.org/en/stable/tutorial.html>`_
28+ Follow the links below to learn more about how to use the Motor driver:
2529
26- - `Documentation <http://motor.readthedocs.org/>`_
30+ - `Tutorial on using Motor with Tornado <http://motor.readthedocs.org/en/stable/tutorial-tornado.html>`__
31+
32+ - `Tutorial on using Motor with asyncio <https://motor.readthedocs.io/en/stable/tutorial-asyncio.html>`__
33+
34+ - `Motor Documentation <http://motor.readthedocs.org/>`__
2735
2836- `Changelog <http://motor.readthedocs.org/en/stable/changelog.html>`__
2937
3038- `Source Code <https://github.com/mongodb/motor/>`__
3139
32- - `Porting From PyMongo To Motor <http://emptysqua.re/blog/porting-from-pymongo-to-motor/>`_
40+ Follow the links below to read blog posts that describe specific use cases
41+ for the Motor driver:
3342
34- - `Refactoring Tornado Coroutines <http://emptysqua.re/blog/refactoring-tornado-coroutines />`_
43+ - `Porting From PyMongo To Motor <http://emptysqua.re/blog/porting-from-pymongo-to-motor />`__
3544
36- - `All Motor articles on A. Jesse Jiryu Davis's blog <http://emptysqua.re/blog/category/motor/>`_
45+ - `Refactoring Tornado Coroutines <http://emptysqua.re/blog/refactoring-tornado-coroutines/>`__
3746
47+ - `All Motor articles on A. Jesse Jiryu Davis's blog <http://emptysqua.re/blog/category/motor/>`__
3848
3949Installation
4050------------
4151
42- We recommend using `pip <http://pypi.python.org/pypi/pip>`__ to install
43- Motor on all platforms:
52+ You must install the Motor driver module to make it available to your Python
53+ application. We recommend using `pip <http://pypi.python.org/pypi/pip>`__
54+ to install Motor.
55+
56+ The following command demonstrates how you can install the latest version of
57+ the module using the command line:
4458
4559.. code-block:: sh
4660
47- $ pip install motor
61+ $ python -m pip install motor
4862
63+ For more information on requirements and other methods of installation,
64+ see the `Motor Installation <https://motor.readthedocs.io/en/stable/installation.html>`__
65+ documentation.
4966
5067Connect to MongoDB Atlas
5168------------------------
5269
5370.. include:: /includes/atlas-connect-blurb.rst
5471
72+ If you are using the ``asyncio`` asynchronous framework, you can use the
73+ following code to connect:
74+
5575.. code-block:: python
5676
77+ import asyncio
78+ import motor.motor_asyncio
79+
80+ async def get_server_info():
81+
82+ # replace this with your MongoDB connection string
83+ conn_str = "<your MongoDB Atlas connection string>"
84+
85+ # set a 5-second connection timeout
86+ client = motor.motor_asyncio.AsyncIOMotorClient(conn_str, serverSelectionTimeoutMS=5000)
87+
88+ try:
89+ print(await client.server_info())
90+ except Exception:
91+ print("Unable to connect to the server.")
92+
93+ loop = asyncio.get_event_loop()
94+ loop.run_until_complete(get_server_info())
95+
96+ If you are using the ``tornado`` asynchronous library, you can use the
97+ following code to connect:
98+
99+ .. code-block:: python
100+
101+ import tornado
57102 import motor
58103
59- client = motor.motor_tornado.MotorClient(
60- "mongodb+srv://<username>:<password>@<cluster-url>/test?retryWrites=true&w=majority")
61- db = client.test
104+ async def get_server_info():
105+
106+ # replace this with your MongoDB connection string
107+ conn_str = "<your MongoDB Atlas connection string>"
108+
109+ # set a 5-second connection timeout
110+ client = motor.motor_tornado.MotorClient(conn_str, serverSelectionTimeoutMS=5000)
111+
112+ try:
113+ print(await client.server_info())
114+ except Exception:
115+ print("Unable to connect to the server.")
116+
117+ tornado.ioloop.IOLoop.current().run_sync(get_server_info)
118+
119+ If the connection succeeds before a five-second timeout, you will see a
120+ dictionary containing information about the server you connected to.
121+
122+ If the connection fails, you should see the following message:
123+
124+ .. code-block:: console
125+ :copyable: false
126+
127+ Unable to connect to the server.
62128
129+ For more information on the connection string, see the MongoDB Server
130+ Manual entry on :manual:`Connection String URI Format </reference/connection-string/>`.
63131
64132Compatibility
65133-------------
0 commit comments