- _filter = {"_id": id}
- collection = self.db[table]
- rows = collection.replace_one(_filter, indata)
+ with self.lock:
+ collection = self.db[table]
+ rows = collection.update_many(self._format_filter(q_filter), {"$set": update_dict})
+ return {"modified": rows.modified_count}
+ except Exception as e: # TODO refine
+ raise DbException(e)
+
+ def replace(self, table, _id, indata, fail_on_empty=True):
+ """
+ Replace the content of an entry
+ :param table: collection or table
+ :param _id: internal database id
+ :param indata: content to replace
+ :param fail_on_empty: If nothing matches filter it returns None unless this flag is set tu True, in which case
+ it raises a DbException
+ :return: Dict with the number of entries replaced
+ """
+ try:
+ db_filter = {"_id": _id}
+ with self.lock:
+ collection = self.db[table]
+ rows = collection.replace_one(db_filter, indata)