PyMongo max_time_ms

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-15 09:55:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!