|
@@ -402,20 +402,31 @@ class MongodbHandler:
|
|
else:
|
|
else:
|
|
return data
|
|
return data
|
|
|
|
|
|
- def update_data_in_collection(self, update_label:str, update_value: str, collection_name:str, query_label: str = None, query_value: str = None, create_if_not_exist: bool = True, find_query: dict = None):
|
|
|
|
|
|
+ def update_data_in_collection(self, update_label:str, update_value: str, collection_name:str, query_label: str = None, query_value: str = None, create_if_not_exist: bool = True, find_query: dict = None, update_many: bool = False):
|
|
|
|
|
|
if isinstance(update_value, pd.DataFrame):
|
|
if isinstance(update_value, pd.DataFrame):
|
|
update_value = simplejson.loads(update_value.to_json(orient="records",
|
|
update_value = simplejson.loads(update_value.to_json(orient="records",
|
|
date_format="iso"))
|
|
date_format="iso"))
|
|
try:
|
|
try:
|
|
- if query_label and query_value:
|
|
|
|
- self._database[collection_name].update_one({query_label:query_value}, {"$set": {update_label: update_value}}, upsert=create_if_not_exist)
|
|
|
|
-
|
|
|
|
- elif find_query:
|
|
|
|
- self._database[collection_name].update_one(find_query, {"$set": {update_label: update_value}}, upsert=create_if_not_exist)
|
|
|
|
|
|
+ if update_many:
|
|
|
|
+ if query_label and query_value:
|
|
|
|
+ self._database[collection_name].update_many({query_label:query_value}, {"$set": {update_label: update_value}}, upsert=create_if_not_exist)
|
|
|
|
+
|
|
|
|
+ elif find_query:
|
|
|
|
+ self._database[collection_name].update_many(find_query, {"$set": {update_label: update_value}}, upsert=create_if_not_exist)
|
|
|
|
+
|
|
|
|
+ else:
|
|
|
|
+ self._database[collection_name].update_many({}, {"$set": {update_label: update_value}}, upsert=create_if_not_exist)
|
|
|
|
|
|
else:
|
|
else:
|
|
- self._database[collection_name].update_one({}, {"$set": {update_label: update_value}}, upsert=create_if_not_exist)
|
|
|
|
|
|
+ if query_label and query_value:
|
|
|
|
+ self._database[collection_name].update_one({query_label:query_value}, {"$set": {update_label: update_value}}, upsert=create_if_not_exist)
|
|
|
|
+
|
|
|
|
+ elif find_query:
|
|
|
|
+ self._database[collection_name].update_one(find_query, {"$set": {update_label: update_value}}, upsert=create_if_not_exist)
|
|
|
|
+
|
|
|
|
+ else:
|
|
|
|
+ self._database[collection_name].update_one({}, {"$set": {update_label: update_value}}, upsert=create_if_not_exist)
|
|
|
|
|
|
self._log.info(('Data for label: {} has been updated').format(update_label))
|
|
self._log.info(('Data for label: {} has been updated').format(update_label))
|
|
|
|
|