@@ -123,14 +123,28 @@ By default, the driver uses only those members whose ping times are within 15 mi
123
123
of the nearest member for queries. To distribute reads between members with
124
124
higher latencies, pass the ``localThresholdMS`` option to the ``MongoClient()`` constructor.
125
125
126
- The following example specifies a local threshold of 35 milliseconds:
126
+ The following example specifies a local threshold of 35 milliseconds. Select the
127
+ :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code:
127
128
128
- .. code-block:: python
129
- :emphasize-lines: 3
129
+ .. tabs::
130
+
131
+ .. tab:: Synchronous
132
+ :tabid: sync
133
+
134
+ .. code-block:: python
135
+
136
+ client = MongoClient(replicaSet='repl0',
137
+ readPreference=ReadPreference.SECONDARY_PREFERRED,
138
+ localThresholdMS=35)
139
+
140
+ .. tab:: Asynchronous
141
+ :tabid: async
130
142
131
- client = MongoClient(replicaSet='repl0',
132
- readPreference=ReadPreference.SECONDARY_PREFERRED,
133
- localThresholdMS=35)
143
+ .. code-block:: python
144
+
145
+ client = AsyncMongoClient(replicaSet='repl0',
146
+ readPreference=ReadPreference.SECONDARY_PREFERRED,
147
+ localThresholdMS=35)
134
148
135
149
In the preceding example, {+driver-short+} distributes reads between matching members
136
150
within 35 milliseconds of the closest member's ping time.
@@ -150,12 +164,27 @@ if they fail due to a network or server error.
150
164
151
165
You can explicitly disable retryable reads or retryable writes by setting the ``retryReads`` or
152
166
``retryWrites`` option to ``False`` in the ``MongoClient()`` constructor. The following
153
- example disables retryable reads and writes for a client:
167
+ example disables retryable reads and writes for a client. Select the
168
+ :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code:
154
169
155
- .. code-block:: python
170
+ .. tabs::
171
+
172
+ .. tab:: Synchronous
173
+ :tabid: sync
174
+
175
+ .. code-block:: python
176
+
177
+ client = MongoClient("<connection string>",
178
+ retryReads=False, retryWrites=False)
179
+
180
+ .. tab:: Asynchronous
181
+ :tabid: async
182
+
183
+ .. code-block:: python
184
+
185
+ client = AsyncMongoClient("<connection string>",
186
+ retryReads=False, retryWrites=False)
156
187
157
- client = MongoClient("<connection string>",
158
- retryReads=False, retryWrites=False)
159
188
160
189
To learn more about supported retryable read operations, see :manual:`Retryable Reads </core/retryable-reads/>`
161
190
in the {+mdb-server+} manual. To learn more about supported retryable write
@@ -170,12 +199,27 @@ you perform on the collection.
170
199
.. include:: /includes/collation-description.rst
171
200
172
201
The following example creates the same collection as the previous example,
173
- but with a default collation of ``fr_CA``:
202
+ but with a default collation of ``fr_CA``. Select the :guilabel:`Synchronous` or
203
+ :guilabel:`Asynchronous` tab to see the corresponding code:
174
204
175
- .. code-block:: python
176
- :emphasize-lines: 4
205
+ .. tabs::
206
+
207
+ .. tab:: Synchronous
208
+ :tabid: sync
177
209
178
- from pymongo.collation import Collation
210
+ .. code-block:: python
211
+
212
+ from pymongo.collation import Collation
213
+
214
+ database = client["test_database"]
215
+ database.create_collection("example_collection", collation=Collation(locale='fr_CA'))
179
216
180
- database = client["test_database"]
181
- database.create_collection("example_collection", collation=Collation(locale='fr_CA'))
217
+ .. tab:: Asynchronous
218
+ :tabid: async
219
+
220
+ .. code-block:: python
221
+
222
+ from pymongo.collation import Collation
223
+
224
+ database = client["test_database"]
225
+ await database.create_collection("example_collection", collation=Collation(locale='fr_CA'))
0 commit comments