@@ -46,39 +46,95 @@ the relevant values for your MongoDB deployment.
4646
4747.. include:: /includes/usage-examples/sample-app-intro.rst
4848
49- .. literalinclude:: /includes/usage-examples/connect-sample-app.py
50- :language: python
51- :copyable: true
52- :linenos:
53- :emphasize-lines: 4-6
49+ Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding
50+ code:
51+
52+ .. tabs::
53+
54+ .. tab:: Synchronous
55+ :tabid: sync
56+
57+ .. literalinclude:: /includes/usage-examples/connect-sample-app.py
58+ :language: python
59+ :copyable: true
60+ :linenos:
61+ :emphasize-lines: 4-6
62+
63+ .. tab:: Asynchronous
64+ :tabid: async
65+
66+ .. literalinclude:: /includes/usage-examples/connect-sample-app-async.py
67+ :language: python
68+ :copyable: true
69+ :linenos:
70+ :emphasize-lines: 6-8
5471
5572Connection
5673----------
5774
5875Local Deployment
5976~~~~~~~~~~~~~~~~
6077
61- .. code-block:: python
78+ .. tabs::
6279
63- uri = "mongodb://localhost:27017/"
64- client = MongoClient(uri)
80+ .. tab:: Synchronous
81+ :tabid: sync
82+
83+ .. code-block:: python
84+
85+ client = MongoClient("mongodb://localhost:27017/")
86+
87+ .. tab:: Asynchronous
88+ :tabid: async
89+
90+ .. code-block:: python
91+
92+ uri = "mongodb://localhost:27017/"
93+ client = AsyncMongoClient(uri)
6594
6695Atlas
6796~~~~~
6897
69- .. code-block:: python
98+ .. tabs::
7099
71- uri = "<Atlas connection string>"
72- client = MongoClient(uri, server_api=pymongo.server_api.ServerApi(
73- version="1", strict=True, deprecation_errors=True))
100+ .. tab:: Synchronous
101+ :tabid: sync
102+
103+ .. code-block:: python
104+
105+ uri = "<Atlas connection string>"
106+ client = MongoClient(uri, server_api=pymongo.server_api.ServerApi(
107+ version="1", strict=True, deprecation_errors=True))
108+
109+ .. tab:: Asynchronous
110+ :tabid: async
111+
112+ .. code-block:: python
113+
114+ uri = "<Atlas connection string>"
115+ client = AsyncMongoClient(uri, server_api=pymongo.server_api.ServerApi(
116+ version="1", strict=True, deprecation_errors=True))
74117
75118Replica Set
76119~~~~~~~~~~~
77120
78- .. code-block:: python
121+ .. tabs::
122+
123+ .. tab:: Synchronous
124+ :tabid: sync
125+
126+ .. code-block:: python
127+
128+ uri = "mongodb://<replica set member>:<port>/?replicaSet=<replica set name>"
129+ client = MongoClient(uri)
79130
80- uri = "mongodb://<replica set member>:<port>/?replicaSet=<replica set name>"
81- client = MongoClient(uri)
131+ .. tab:: Asynchronous
132+ :tabid: async
133+
134+ .. code-block:: python
135+
136+ uri = "mongodb://<replica set member>:<port>/?replicaSet=<replica set name>"
137+ client = AsyncMongoClient(uri)
82138
83139Network Compression
84140-------------------
@@ -115,29 +171,76 @@ zlib Compression Level
115171 "zlibCompressionLevel=<zlib compression level>")
116172 client = pymongo.MongoClient(uri)
117173
174+ .. tab:: MongoClient (Asynchronous)
175+ :tabid: mongoclient-async
176+
177+ .. code-block:: python
178+
179+ client = pymongo.AsyncMongoClient("mongodb://<db_username>:<db_password>@<hostname>:<port>",
180+ compressors = "zlib",
181+ zlibCompressionLevel=<zlib compression level>)
182+
183+ .. tab:: Connection String (Asynchronous)
184+ :tabid: connectionstring-async
185+
186+ .. code-block:: python
187+
188+ uri = ("mongodb://<db_username>:<db_password>@<hostname>:<port>/?"
189+ "compressors=zlib"
190+ "zlibCompressionLevel=<zlib compression level>")
191+ client = pymongo.AsyncMongoClient(uri)
192+
118193To learn more about setting the zlib compression level, see
119194:ref:`pymongo-enable-compression` in the Network Compression guide.
120195
121196Server Selection
122197----------------
123198
124- .. code-block:: python
199+ .. tabs::
125200
126- client = pymongo.MongoClient("mongodb://<db_username>:<db_password>@<hostname>:<port>",
127- server_selector=<selector function>)
201+ .. tab:: Synchronous
202+ :tabid: sync
203+
204+ .. code-block:: python
205+
206+ client = pymongo.MongoClient("mongodb://<db_username>:<db_password>@<hostname>:<port>",
207+ server_selector=<selector function>)
208+
209+ .. tab:: Asynchronous
210+ :tabid: async
211+
212+ .. code-block:: python
213+
214+ client = pymongo.AsyncMongoClient("mongodb://<db_username>:<db_password>@<hostname>:<port>",
215+ server_selector=<selector function>)
128216
129217To learn more about customizing server selection, see
130218:ref:`pymongo-server-selection`.
131219
132220{+stable-api+}
133221--------------
134222
135- .. code-block:: python
223+ .. tabs::
136224
137- from pymongo.server_api import ServerApi
225+ .. tab:: Synchronous
226+ :tabid: sync
138227
139- client = pymongo.MongoClient("mongodb://<db_username>:<db_password>@<hostname:<port>",
140- server_api=ServerApi("<{+stable-api+} version>"))
228+ .. code-block:: python
229+
230+ from pymongo.server_api import ServerApi
231+
232+ client = pymongo.MongoClient("mongodb://<db_username>:<db_password>@<hostname:<port>",
233+ server_api=ServerApi("<{+stable-api+} version>"))
234+
235+ .. tab:: Asynchronous
236+ :tabid: async
237+
238+ .. code-block:: python
239+
240+ from pymongo.server_api import ServerApi
241+
242+ client = pymongo.AsyncMongoClient("mongodb://<db_username>:<db_password>@<hostname:<port>",
243+ server_api=ServerApi("<{+stable-api+} version>"))
141244
142245To learn more about the {+stable-api+}, see :ref:`pymongo-stable-api`.
143246
@@ -175,5 +278,20 @@ timeoutMS Connection Option
175278 uri = "mongodb://<db_username>:<db_password>@<hostname:<port>/?timeoutMS=<timeout length>"
176279 client = pymongo.MongoClient(uri)
177280
178- To learn more about client-side timeouts, see :ref:`pymongo-csot`.
281+ .. tab:: MongoClient (Asynchronous)
282+ :tabid: mongoclient-async
179283
284+ .. code-block:: python
285+
286+ client = pymongo.AsyncMongoClient("mongodb://<db_username>:<db_password>@<hostname@:<port>",
287+ timeoutMS=<timeout length>)
288+
289+ .. tab:: Connection String (Asynchronous)
290+ :tabid: connectionstring-async
291+
292+ .. code-block:: python
293+
294+ uri = "mongodb://<db_username>:<db_password>@<hostname:<port>/?timeoutMS=<timeout length>"
295+ client = pymongo.AsyncMongoClient(uri)
296+
297+ To learn more about client-side timeouts, see :ref:`pymongo-csot`.
0 commit comments