【发布时间】:2014-08-03 16:23:46
【问题描述】:
我正在尝试使用以下代码获取 mongo 数据库中存在的一些 id:
client = MongoClient('xx.xx.xx.xx', xxx)
db = client.test_database
db = client['...']
collection = db.test_collection
collection = db["..."]
for cursor in collection.find({ "$and" : [{ "followers" : { "$gt" : 2000 } }, { "followers" : { "$lt" : 3000 } }, { "list_followers" : { "$exists" : False } }] }):
print cursor['screenname']
print cursor['_id']['uid']
id = cursor['_id']['uid']
但是,过了一会儿,我收到了这个错误:
pymongo.errors.CursorNotFound: cursor id '...' 在服务器上无效。
我发现这个article 指的是那个问题。然而,我不清楚采取哪种解决方案。是否可以使用find().batch_size(30)?上面的命令具体是做什么的?我可以使用 batch_size 获取所有数据库 ID 吗?
【问题讨论】:
-
我意识到我忘记关闭光标
cursor.close()