projects
/
osm
/
common.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Pinning version of flake8
[osm/common.git]
/
osm_common
/
dbmongo.py
diff --git
a/osm_common/dbmongo.py
b/osm_common/dbmongo.py
index
8561e96
..
e5e12c6
100644
(file)
--- 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):
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
self.client = None
self.db = None
self.database_key = None
@@
-105,13
+105,6
@@
class DbMongo(DbBase):
self.client = MongoClient(
config["uri"], replicaSet=config.get("replicaset", None)
)
self.client = MongoClient(
config["uri"], replicaSet=config.get("replicaset", None)
)
- else:
- self.client = MongoClient(
- config["host"],
- config["port"],
- replicaSet=config.get("replicaset", None),
- )
- # TODO add as parameters also username=config.get("user"), password=config.get("password"))
# when all modules are ready
self.db = self.client[config["name"]]
if "loglevel" in config:
# when all modules are ready
self.db = self.client[config["name"]]
if "loglevel" in config:
@@
-291,7
+284,7
@@
class DbMongo(DbBase):
with self.lock:
collection = self.db[table]
db_filter = self._format_filter(q_filter)
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
return count
except DbException:
raise
@@
-315,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)
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(
if fail_on_empty:
raise DbException(
"Not found any {} with filter='{}'".format(
@@
-324,8
+317,9
@@
class DbMongo(DbBase):
),
HTTPStatus.NOT_FOUND,
)
),
HTTPStatus.NOT_FOUND,
)
+
return None
return None
- elif
rows.count(
) > 1:
+ elif
len(rows
) > 1:
if fail_on_more:
raise DbException(
"Found more than one {} with filter='{}'".format(
if fail_on_more:
raise DbException(
"Found more than one {} with filter='{}'".format(