pymongo : to check if we have connected to MongoDB database
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 2 Looping
--
Chapters
00:00 Pymongo : To Check If We Have Connected To Mongodb Database
01:06 Accepted Answer Score 1
01:23 Thank you
--
Full question
https://stackoverflow.com/questions/4322...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #django #mongodb #pymongo
#avk47
    Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 2 Looping
--
Chapters
00:00 Pymongo : To Check If We Have Connected To Mongodb Database
01:06 Accepted Answer Score 1
01:23 Thank you
--
Full question
https://stackoverflow.com/questions/4322...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #django #mongodb #pymongo
#avk47
ACCEPTED ANSWER
Score 1
You will probably have to use the authenticate method anyway inside connection function, so you could do it as following:
In [12]: client = MongoClient(DB_MACHINE, DB_PORT)
In [13]: db = client.db_name
In [16]: if db.authenticate(DB_USER, DB_PASS, source=DB_SOURCE):
             # authenticated, do ...
         else:
             # not authenticated, not connected, do something else