PyMongo max_time_ms [英] PyMongo max_time_ms

查看:100
本文介绍了PyMongo max_time_ms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在mongodb上的查找过程中使用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_ms(500)

有什么办法可以验证?
我尝试了db.fsyncLock(),但是我知道这仅适用于插入.

Is there any way to verify?
I tried to db.fsyncLock(), but I get this is applicable only for inserts.

我认为可能的解决方案是插入太多条目并减少为max_time_ms(1),这样查询将没有足够的时间来获取结果.

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.

有什么建议吗? Tks

Any suggestions? Tks

推荐答案

以这种方式传递max_time_ms选项

cursor = db.collection.find().max_time_ms(1)

cursor = db.collection.find(max_time_ms=1)

设置查询的时间限制,并在超出查询的指定时间限制时出错,并显示pymongo.errors.ExecutionTimeout异常.

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(可选):指定查询的时间限制 手术.如果超过指定的时间,则将执行 中止,并引发:exc:~pymongo.errors.ExecutionTimeout.经过 这可以代替打电话 [来源:文档]

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]

这篇关于PyMongo max_time_ms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆