I am using mongoengine v0.15.0. How to fetch the name of the database connected to? Of course, I would have supplied the name in the uri string. But, is there a way to
All the information about the DB connection created in the mongoengine can be found by calling get_db() which returns a pymongo.database.Database
object. Then you can access the database name in the attribute name
. Here is an example.
from mongoengine.connection import get_db, connect
connect("test_db")
# Then, somewhere where you want to get the DB name
db = get_db()
print("Database name: ", db.name)
The output:
Database name: test_db