多标志我的工作pymongo,这是我的文档:的Upsert和pymongo
{
"_id": ObjectId("51211b57f07ddaa377000000"),
"assignments": {
"0": {
"0": {
"_id": ObjectId("5120dd7400a4453d58a0d0ec")
},
"1": {
"_id": ObjectId("5120dd8e00a4453d58a0d0ed")
},
"2": {
"_id": ObjectId("5120ddad00a4453d58a0d0ee")
}
}
},
"password": "my_passwd",
"username": "john"
}
我想取消设置所有这些文档的“分配”属性。 我能够这样做,以实现这一在蒙戈外壳:
db.users.update({}, {$unset: {"assignments": 1}}, false, true)
即,我通过UPSERT和多标志作为最后两个参数对用户收集的更新功能功能。 但是我这样做与pymongo:
db.users.update({}, {"$unset": {"assignments": 1}}, False, True)
但是Python解释如下抛出一个错误:
File "notes/assignment.py", line 34, in <module>
db.users.update({}, {"$unset": {"assignments": 1}}, False, True)
File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 481, in update
check_keys, self.__uuid_subtype), safe)
File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 852, in _send_message
rv = self.__check_response_to_last_error(response)
File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 795, in __check_response_to_last_error
raise OperationFailure(details["err"], details["code"])
pymongo.errors.OperationFailure: Modifiers and non-modifiers cannot be mixed
我要去哪里错了?
看看http://stackoverflow.com/questions/14443478/remove-subfields-from-mongodb-document也许你会发现一些熟悉的东西 – mderk 2013-02-17 20:19:37