Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Mongodb受批大小限制超时_Python_Mongodb_Collections_Timeout_Pymongo - Fatal编程技术网

Python Mongodb受批大小限制超时

Python Mongodb受批大小限制超时,python,mongodb,collections,timeout,pymongo,Python,Mongodb,Collections,Timeout,Pymongo,我正试图抓取一个巨大的(5gb)mongo数据库,因此为了便于管理,我限制了批量大小。但是,我仍然得到一个超时错误:/ 我的mongo知识是公认的不是最好的,所以如果我做了一些完全愚蠢的事情,请让我知道!我已经搜索了文档和其他问题,但没有一个答案有用 以下是我想做的: from pymongo import MongoClient collection = MongoClient(host="mongodb://xxx@xxx") cursor = collection.all_compani

我正试图抓取一个巨大的(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:超时


要从查询结果中获取多个文档,我们使用find()方法。find()返回一个游标实例,它允许我们遍历所有匹配的文档


我不在乎我得到多少物品,我只是不想服务器超时。当我不限制批量大小时,它肯定会超时
connection = MongoClient(host="mongodb://xxx@xxx")
collection = connection.all_companies.companies
for item in collection.find():
    print item