Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use update_one instead of findAndModify for update operations #738

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions mongo_connector/doc_managers/mongo_doc_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,11 @@ def update(self, document_id, update_spec, namespace, timestamp):
"_ts": timestamp,
"ns": namespace},
upsert=True)

no_obj_error = "No matching object found"
updated = self.mongo[db].command(
SON([('findAndModify', coll),
('query', {'_id': document_id}),
('update', update_spec),
('new', True)]),
allowable_errors=[no_obj_error])['value']

if( "$set" not in update_spec and "$unset" not in update_spec ):
update_spec = {"$set": update_spec} # python requires a dollar sign operator
updated = self.mongo[db][coll].update_one({'_id': document_id}, update_spec )

return updated

@wrap_exceptions
Expand Down Expand Up @@ -240,7 +237,7 @@ def iterate_chunks():
+ str(e))
except pymongo.errors.BulkWriteError as bwe:
LOG.error(bwe.details)
raise e
raise bwe

@wrap_exceptions
def remove(self, document_id, namespace, timestamp):
Expand Down