Skip to content

Commit

Permalink
PY: check if connection successful
Browse files Browse the repository at this point in the history
differently with updated verion of pymongo
  • Loading branch information
Stanislav Tereshchenko committed Dec 14, 2017
1 parent 9ab7a95 commit 4c86c96
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/python/urb/db/urb_mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class URBMongoClient(object):
def __init__(self, db_uri='mongodb://localhost:27017/', db_name=DB_NAME, expire=TTL_MONTHS):
self.logger = LogManager.get_instance().get_logger(self.__class__.__name__)
try:
# for pymongo >= 3.0 constructor doesn't throw anymore
self.client = MongoClient(db_uri)
# check connection with ismaster command
self.client.admin.command('ismaster')
self.logger.info("Connected to Mongo DB: %s" % db_uri)
self.db = self.client[db_name]
self.expire = expire
Expand Down

0 comments on commit 4c86c96

Please sign in to comment.