How to get a list of all databases in a mongo instance using pymongo

how to get a list of all databases in a mongo instance for a variable using pymongo?

for example to send the following command to a mongo instance using pymongo,

db.adminCommand ({listDatabases: 1})

+5


source to share


1 answer


Use database_names

dbs = MongoClient().database_names()

      



As Andrew Aller points out: As of pymongo 3.6, database_names () has been deprecated in favor of list_database_names .

dbs = MongoClient().list_database_names()

      

+7


source







All Articles