问题
I would like to use the max_time_ms flag during a find on mongodb, but I woulld like to understand how this flag works and how to verify that it is working.
pymongo find().max_time_ms(500)
Is there any way to verify?
I tried to db.fsyncLock()
, but I get this is applicable only for inserts.
I thought that a possible solution should be insert too many entries and reduce to max_time_ms(1)
, so the query will not have enough time to take results.
Any suggestions? Tks
回答1:
Passing the max_time_ms
option this way
cursor = db.collection.find().max_time_ms(1)
or
cursor = db.collection.find(max_time_ms=1)
sets a time limit for the query and errors out with a pymongo.errors.ExecutionTimeout
exception when the time limit specified is exceeded for the query.
Since cursors are lazy, this exception is raised when accessing results from the cursor e.g.
for doc in cursor:
print(doc)
ExecutionTimeout: operation exceeded time limit
max_time_ms
(optional): Specifies a time limit for a query operation. If the specified time is exceeded, the operation will be aborted and :exc:~pymongo.errors.ExecutionTimeout
is raised. Pass this as an alternative to calling [Source: Docs]
来源:https://stackoverflow.com/questions/48809884/pymongo-max-time-ms