我正在尝试抓取一个巨大的(5GB)mongo 数据库,因此我限制了批量大小以便易于管理。但是,我仍然收到超时错误:/
我的 mongo 知识确实不是最好的,所以如果我做了一些完全愚蠢的事情,请告诉我!我已经搜索了文档和其他问题,但没有一个答案有帮助。
这是我正在尝试做的事情:
from pymongo import MongoClient
collection = MongoClient(host="mongodb://xxx@xxx")
cursor = collection.all_companies.companies
batch = cursor.find().batch_size(1).limit(1) # I tried w/ other numbers too
for item in batch:
print item
这就是我得到的:
pymongo.errors.ServerSelectionTimeoutError: xxx:xxx: timed out
最佳答案
要获取多个文档作为查询结果,我们使用 find() 方法。 find() 返回一个 Cursor 实例,它允许我们迭代所有匹配的文档。
connection = MongoClient(host="mongodb://xxx@xxx")
collection = connection.all_companies.companies
for item in collection.find():
print item
关于Python Mongodb 通过批量大小限制超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38003846/