Skip to content Skip to sidebar Skip to footer

Pymongo Max_time_ms

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

Solution 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]

Post a Comment for "Pymongo Max_time_ms"