PyMongo List Database Names
To list databases present in a MongoDB instance,
- Create a client to the MongoDB instance.
- Using the client, call list_databases() function.
- The functions returns an iterator, use for loop to iterate through the list of databases.
Example 1: List Databases present in MongoDB
import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
for db in myclient.list_databases():
print(db)
Run Output
