X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2Fcommon.git;a=blobdiff_plain;f=osm_common%2Fdbmongo.py;h=86ec7b79c46590ab31b122f2eaa5e6610a4def4a;hp=5334ef91ecbcadc00dc3930cdc32c421a21ee905;hb=ae049d8467e5ce1b1be8487ed93031b594dc0230;hpb=6472e2b6e90c263b59c1195a952fbf4b7d35eba0 diff --git a/osm_common/dbmongo.py b/osm_common/dbmongo.py index 5334ef9..86ec7b7 100644 --- a/osm_common/dbmongo.py +++ b/osm_common/dbmongo.py @@ -221,6 +221,25 @@ class DbMongo(DbBase): except Exception as e: # TODO refine raise DbException(e) + def count(self, table, q_filter=None): + """ + Count the number of entries matching q_filter + :param table: collection or table + :param q_filter: Filter + :return: number of entries found (can be zero) + :raise: DbException on error + """ + try: + with self.lock: + collection = self.db[table] + db_filter = self._format_filter(q_filter) + count = collection.count(db_filter) + return count + except DbException: + raise + except Exception as e: # TODO refine + raise DbException(e) + def get_one(self, table, q_filter=None, fail_on_empty=True, fail_on_more=True): """ Obtain one entry matching q_filter