In this example we will show how to check if a database exists by listing all databases in your system in Python MongoDB.
Source Code
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
print(client.list_database_names())
Output:
['admin', 'config', 'local', 'mydatabase']