tôi đang làm việc trên pymongo và đây là tài liệu của tôi:Upsert và cờ đa trong pymongo
{
"_id": ObjectId("51211b57f07ddaa377000000"),
"assignments": {
"0": {
"0": {
"_id": ObjectId("5120dd7400a4453d58a0d0ec")
},
"1": {
"_id": ObjectId("5120dd8e00a4453d58a0d0ed")
},
"2": {
"_id": ObjectId("5120ddad00a4453d58a0d0ee")
}
}
},
"password": "my_passwd",
"username": "john"
}
Tôi muốn bỏ đặt "chuyển nhượng" tài sản của tất cả các tài liệu như vậy. tôi đã có thể đạt được điều này trên vỏ Mongo bằng cách thực hiện:
db.users.update({}, {$unset: {"assignments": 1}}, false, true)
ví dụ, tôi đã thông qua upsert và đa cờ như hai tham số cuối cùng để các chức năng cập nhật chức năng trên bộ sưu tập người dùng. Tuy nhiên tôi đã làm điều này với pymongo:
db.users.update({}, {"$unset": {"assignments": 1}}, False, True)
Nhưng người phiên dịch python ném một lỗi như sau:
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
tôi đi đâu vậy?
nhìn vào http://stackoverflow.com/questions/14443478/remove-subfields-from-mongodb-document có thể bạn sẽ tìm thấy một cái gì đó quen thuộc – mderk