def meta_update(self, obj_id, meta: Mapping): try: to_set = queries.expand_filter(db.META, meta) res = self._data_collection.update_one({'_id': obj_id}, {'$set': to_set}, upsert=False) except pymongo.errors.DuplicateKeyError as exc: raise exceptions.DuplicateKeyError(str(exc)) else: if res.matched_count == 0: raise exceptions.NotFound( f"No record with object id '{obj_id}' found")
def load(self, snapshot_id: records.SnapshotId) -> records.DataRecord: if not isinstance(snapshot_id, records.SnapshotId): raise TypeError(snapshot_id) results = tuple( self._history_collection.find({ db.OBJ_ID: snapshot_id.obj_id, db.VERSION: snapshot_id.version })) if not results: raise exceptions.NotFound(f"Snapshot id '{snapshot_id}' not found") return db.to_record(results[0])
def meta_set(self, obj_id, meta): try: found = self._data_collection.update_one({'_id': obj_id}, {'$set': { db.META: meta }}, upsert=False) except pymongo.errors.DuplicateKeyError as exc: raise exceptions.DuplicateKeyError(str(exc)) else: if found.modified_count == 0: raise exceptions.NotFound( f"No record with object id '{obj_id}' found")
def get(self, entry_id: bson.ObjectId) -> dict: doc = self._collection.find_one({'_id': entry_id}) # type: dict if doc is None: raise exceptions.NotFound(entry_id) return db.remap_back(doc)