简体   繁体   English

[PYMONGO]:在查询中传递 sockettimeout

[英][PYMONGO]: Passing sockettimeout in a query

print(db.command({"count":"collection_name",
                          "query": {"col":"col_value"}},
                          {"socketTimeoutMS":12000}))

I saw a query in php it passes socket timeout in the query itself.So,I tried the above query in pymongo but it is not working.我在 php 中看到一个查询,它在查询本身中传递了套接字超时。所以,我在 pymongo 中尝试了上述查询,但它不起作用。

Is there any way to pass socket timeout through a query.有没有办法通过查询传递套接字超时。

You pass the 'socketTimeoutMS' value while initializing the MongoClient object.您在初始化 MongoClient 对象时传递 'socketTimeoutMS' 值。 Something like this:像这样的东西:

import pymongo
client = pymongo.MongoClient(host='your.host.ip.address', socketTimeoutMS=12000)
db = client['db_name']
print(db.command(
    {
        "count":"collection_name", 
        "query": {"col":"col_value"}
    }
))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM