python - Why does upsert a record using update_one raise ValueError? -
i want add record collection if key doesn't exist. understand [mongodb][1] offers upsertfor did
db.collection.update({"_id":"key1"},{"_id":"key1"},true) this seems work.
however in pymongo documentation says update deprecated , use update_one().
but:
db.collection.update_one({"_id":"key1"},{"_id":"key1"},true) gives:
raise valueerror('update works $ operators') valueerror: update works $ operators i don't understand why update_one different , why need use $ operator. can help?
this because didn't specify update operator. example $set id value use:
db.collection.update_one({"_id":"key1"}, {"$set": {"id":"key1"}}, upsert=true) note in mongo shell, replace document new document.
Comments
Post a Comment