Update existing document #1899
This commit is contained in:
parent
34e3e45843
commit
47577f2f47
@ -436,6 +436,13 @@ class Document(six.with_metaclass(TopLevelDocumentMetaclass, BaseDocument)):
|
|||||||
with set_write_concern(collection, write_concern) as wc_collection:
|
with set_write_concern(collection, write_concern) as wc_collection:
|
||||||
if force_insert:
|
if force_insert:
|
||||||
return wc_collection.insert_one(doc).inserted_id
|
return wc_collection.insert_one(doc).inserted_id
|
||||||
|
# insert_one will provoke UniqueError alongside save does not
|
||||||
|
# therefore, it need to catch and call replace_one.
|
||||||
|
if '_id' in doc:
|
||||||
|
raw_object = wc_collection.find_one_and_replace(
|
||||||
|
{'_id': doc['_id']}, doc)
|
||||||
|
if raw_object:
|
||||||
|
return doc['_id']
|
||||||
|
|
||||||
object_id = wc_collection.insert_one(doc).inserted_id
|
object_id = wc_collection.insert_one(doc).inserted_id
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user