I am trying to update all the properties of a record / object that are stored in MongoDB, now I am trying to do this.
- The object is deleted, but the identifier of the deleted object is saved.
- Create a new object with the same identifier that I deleted.
Is it correct? or what to do on objects using pymongo?
mongo_object = {
_id : 123,
prop_key_1: some_value,
// ... many present
prop_key_n: some_value,
}
def delete(record):
doc = get_db().reviews.delete_many({"id" : record["_id"]})
print(doc.deleted_count)
delete(mongo_object)
db.collection_name.insert_one(mongo_object)
But the above code does not delete the object, it doc.deleted_countis 0.
source
share