![](/img/trans.png)
[英]How to solve attribute error: 'Cursor' object has no attribute 'noCursorTimeout' in pymongo?
[英]How do I solve this error of Pymongo? cursor id not found pymongo
我在 MongoDB 中获取了一些集合的全部数据,过了一段时间(如 30 或 60 分钟),脚本引发以下错误:
pymongo.errors.CursorNotFound: cursor id 1801580172063793986 not found, full error: {'ok': 0.0, 'errmsg': 'cursor id 1801580172063793986 not found', 'code':
此错误发生在 24k 文档之后。 我正在使用 Django 和 Pymongo 连接到本地服务器中的数据库。 该集合有大约 60k 个文档。
这就是我获取数据的方式:
client = MongoClient(settings.MONGO_HOST, settings.MONGO_PORT)
collection = client[settings.MONGO_DB].collection
cursor = collection.find(no_cursor_timeout=True)
for document in cursor:
# getting the data from the user
以防万一,我正在使用:
这不是错误的解决方案,但这是避免错误的一种方法。 为了在最短的时间内使用 cursor,您可以将所有数据保存在列表或类似的东西中。
client = MongoClient(settings.MONGO_HOST, settings.MONGO_PORT)
collection = client[settings.MONGO_DB].collection
cursor = collection.find(no_cursor_timeout=True)
collection_data = [document for document in cursor]
for document in collection_data:
# using the data
尝试通过cursorTimeoutMillis
参数全局设置 cursor 超时。
在您的终端中,键入:
$ mongod --setParameter cursorTimeoutMillis=600000
请参阅https://jira.mongodb.org/browse/SERVER-36808和相关的链接票证。
服务器可以销毁打开的游标正在使用的会话,这具有使这些游标不可用的效果。
https://jira.mongodb.org/browse/PYTHON-1626可能会有所帮助,尽管在我看来问题出在服务器端并且目前尚未解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.