在 mongo
命令行中我可以运行
db.my_collection.stats()
我需要从 Python
获取我的收藏统计信息,所以我尝试了
from pymongo import MongoClient
client = MongoClient()
db = client.test_database
collection = db.test_collection
collection.stats()
但是我明白了
TypeError: 'Collection' object is not callable.
If you meant to call the 'stats' method on a 'Collection' object it is failing because no such method exists.
这是因为pymongo
不支持该方法。如何通过 Python
将原始 mongoDB
命令发送到 mongo
?
最佳答案
from pymongo import MongoClient
client = MongoClient()
db = client.test_database
print(db.command("collstats", "test_collection"))
关于python - 如何从 pymongo 运行原始 mongodb 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27297727/