pymongo: 全局名称 'ReturnDocument' 未定义
pymongo: global name 'ReturnDocument' is not defined
我正在尝试编写一个 python 程序来查找和更新 mongodb 中的文档:
db.collection.find_one_and_update({"Machine": "24", "Available": True},
{"$set": {"Overview.Available": False}},
projection= {"_id": 0, "Machine": 1, "Available": 1},
return_document= ReturnDocument.AFTER)
但我收到以下错误消息(显然我没有正确使用 return_document 但所有 pymongo 文档都说我是)
NameError: global name 'ReturnDocument' is not defined
您需要先导入 ReturnDocument
class。将此添加到脚本的顶部:
from pymongo.collection import ReturnDocument
详细文档:http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.ReturnDocument
我正在尝试编写一个 python 程序来查找和更新 mongodb 中的文档:
db.collection.find_one_and_update({"Machine": "24", "Available": True},
{"$set": {"Overview.Available": False}},
projection= {"_id": 0, "Machine": 1, "Available": 1},
return_document= ReturnDocument.AFTER)
但我收到以下错误消息(显然我没有正确使用 return_document 但所有 pymongo 文档都说我是)
NameError: global name 'ReturnDocument' is not defined
您需要先导入 ReturnDocument
class。将此添加到脚本的顶部:
from pymongo.collection import ReturnDocument
详细文档:http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.ReturnDocument