how to get the list of all the databases in a mongo instance to a variable using pymongo?
for example to send following command to mongo instance using pymongo,
db.adminCommand( { listDatabases: 1 } )
Use database_names
dbs = MongoClient().database_names()
As Andrew Allaire points out: Starting in pymongo 3.6 database_names() has been deprecated in favour of list_database_names.
dbs = MongoClient().list_database_names()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With