This example will connect to the MongoDB running at localhost
(on the default port 27017
) without any username or password and open the database named mydb
(also see Python MongoDB minimal connect example using pymongo) and list all the collection names in mydb
:
from pymongo import MongoClient client = MongoClient("mongodb://localhost") db = client["mydb"] print(db.list_collection_names())
This will print, for example,
['people', 'salaries']