File tree Expand file tree Collapse file tree 4 files changed +40
-0
lines changed Expand file tree Collapse file tree 4 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -767,6 +767,8 @@ async def explain(self) -> _DocumentType:
767
767
:meth:`~pymongo.asynchronous.database.AsyncDatabase.command` to run the explain
768
768
command directly.
769
769
770
+ .. note:: The timeout of this method can be set using :func:`pymongo.timeout`.
771
+
770
772
.. seealso:: The MongoDB documentation on `explain <https://dochub.mongodb.org/core/explain>`_.
771
773
"""
772
774
c = self .clone ()
Original file line number Diff line number Diff line change @@ -765,6 +765,8 @@ def explain(self) -> _DocumentType:
765
765
:meth:`~pymongo.database.Database.command` to run the explain
766
766
command directly.
767
767
768
+ .. note:: The timeout of this method can be set using :func:`pymongo.timeout`.
769
+
768
770
.. seealso:: The MongoDB documentation on `explain <https://dochub.mongodb.org/core/explain>`_.
769
771
"""
770
772
c = self .clone ()
Original file line number Diff line number Diff line change @@ -362,6 +362,24 @@ async def test_explain_with_read_concern(self):
362
362
self .assertEqual (len (started ), 1 )
363
363
self .assertNotIn ("readConcern" , started [0 ].command )
364
364
365
+ # https://github.com/mongodb/specifications/blob/master/source/crud/tests/README.md#14-explain-helpers-allow-users-to-specify-maxtimems
366
+ async def test_explain_csot (self ):
367
+ # Create a MongoClient with command monitoring enabled (referred to as client).
368
+ listener = AllowListEventListener ("explain" )
369
+ client = await self .async_rs_or_single_client (event_listeners = [listener ])
370
+
371
+ # Create a collection, referred to as collection, with the namespace explain-test.collection.
372
+ collection = client ["explain-test" ]["collection" ]
373
+
374
+ # Run an explained find on collection. The find will have the query predicate { name: 'john doe' }. Specify a maxTimeMS value of 2000ms for the explain.
375
+ with pymongo .timeout (2.0 ):
376
+ self .assertTrue (await collection .find ({"name" : "john doe" }).explain ())
377
+
378
+ # Obtain the command started event for the explain. Confirm that the top-level explain command should has a maxTimeMS value of 2000.
379
+ started = listener .started_events
380
+ self .assertEqual (len (started ), 1 )
381
+ assert 1500 < started [0 ].command ["maxTimeMS" ] <= 2000
382
+
365
383
async def test_hint (self ):
366
384
db = self .db
367
385
with self .assertRaises (TypeError ):
Original file line number Diff line number Diff line change @@ -354,6 +354,24 @@ def test_explain_with_read_concern(self):
354
354
self .assertEqual (len (started ), 1 )
355
355
self .assertNotIn ("readConcern" , started [0 ].command )
356
356
357
+ # https://github.com/mongodb/specifications/blob/master/source/crud/tests/README.md#14-explain-helpers-allow-users-to-specify-maxtimems
358
+ def test_explain_csot (self ):
359
+ # Create a MongoClient with command monitoring enabled (referred to as client).
360
+ listener = AllowListEventListener ("explain" )
361
+ client = self .rs_or_single_client (event_listeners = [listener ])
362
+
363
+ # Create a collection, referred to as collection, with the namespace explain-test.collection.
364
+ collection = client ["explain-test" ]["collection" ]
365
+
366
+ # Run an explained find on collection. The find will have the query predicate { name: 'john doe' }. Specify a maxTimeMS value of 2000ms for the explain.
367
+ with pymongo .timeout (2.0 ):
368
+ self .assertTrue (collection .find ({"name" : "john doe" }).explain ())
369
+
370
+ # Obtain the command started event for the explain. Confirm that the top-level explain command should has a maxTimeMS value of 2000.
371
+ started = listener .started_events
372
+ self .assertEqual (len (started ), 1 )
373
+ assert 1500 < started [0 ].command ["maxTimeMS" ] <= 2000
374
+
357
375
def test_hint (self ):
358
376
db = self .db
359
377
with self .assertRaises (TypeError ):
You can’t perform that action at this time.
0 commit comments