From 50bdfe6260cf0ec63f9ce36bec479db447fc2305 Mon Sep 17 00:00:00 2001 From: TJ Date: Tue, 20 Jun 2017 23:17:50 +0800 Subject: [PATCH 1/2] fix typo error: bwe --- mongo_connector/doc_managers/mongo_doc_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongo_connector/doc_managers/mongo_doc_manager.py b/mongo_connector/doc_managers/mongo_doc_manager.py index 2918a733..63dfbaf3 100644 --- a/mongo_connector/doc_managers/mongo_doc_manager.py +++ b/mongo_connector/doc_managers/mongo_doc_manager.py @@ -240,7 +240,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): From c1c7c998c8c7b207d1ffa4a678b9af0952feffaa Mon Sep 17 00:00:00 2001 From: TJ Date: Fri, 1 Sep 2017 07:52:40 +0800 Subject: [PATCH 2/2] changing findAndModify to update_one for update operation --- mongo_connector/doc_managers/mongo_doc_manager.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/mongo_connector/doc_managers/mongo_doc_manager.py b/mongo_connector/doc_managers/mongo_doc_manager.py index 63dfbaf3..3aa34027 100644 --- a/mongo_connector/doc_managers/mongo_doc_manager.py +++ b/mongo_connector/doc_managers/mongo_doc_manager.py @@ -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