简体   繁体   中英

[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.

Is there any way to pass socket timeout through a query.

You pass the 'socketTimeoutMS' value while initializing the MongoClient object. 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"}
    }
))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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