How to Check If a Database Exists By Listing All Databases in Python


In this example, we will learn 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']
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments