X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_common%2Fdbmongo.py;h=e5e12c67b1868735cc4def86907aa67accba6680;hb=HEAD;hp=f64949d50a612884ef786d04dc72ceb0fa6bd8f8;hpb=7da9795a4b73c72e81ac4880a9e9507e441aa90f;p=osm%2Fcommon.git diff --git a/osm_common/dbmongo.py b/osm_common/dbmongo.py index f64949d..e5e12c6 100644 --- a/osm_common/dbmongo.py +++ b/osm_common/dbmongo.py @@ -65,7 +65,7 @@ class DbMongo(DbBase): conn_timout = 10 def __init__(self, logger_name="db", lock=False): - super().__init__(logger_name, lock) + super().__init__(logger_name=logger_name, lock=lock) self.client = None self.db = None self.database_key = None @@ -284,7 +284,7 @@ class DbMongo(DbBase): with self.lock: collection = self.db[table] db_filter = self._format_filter(q_filter) - count = collection.count(db_filter) + count = collection.count_documents(db_filter) return count except DbException: raise @@ -308,8 +308,8 @@ class DbMongo(DbBase): collection = self.db[table] if not (fail_on_empty and fail_on_more): return collection.find_one(db_filter) - rows = collection.find(db_filter) - if rows.count() == 0: + rows = list(collection.find(db_filter)) + if len(rows) == 0: if fail_on_empty: raise DbException( "Not found any {} with filter='{}'".format( @@ -317,8 +317,9 @@ class DbMongo(DbBase): ), HTTPStatus.NOT_FOUND, ) + return None - elif rows.count() > 1: + elif len(rows) > 1: if fail_on_more: raise DbException( "Found more than one {} with filter='{}'".format(