pymongo: MongoDB-Collection-Namen in Python auflisten
English
Deutsch
Dieses Beispiel verbindet sich mit der MongoDB auf localhost (Standardport 27017) ohne Benutzername oder Passwort und öffnet die Datenbank namens mydb (siehe auch Python MongoDB minimal connect example using pymongo) und listet alle Collection-Namen in mydb auf:
mongodb_list_collections.py
from pymongo import MongoClient
client = MongoClient("mongodb://localhost")
db = client["mydb"]
print(db.list_collection_names())Dies gibt beispielsweise aus:
mongodb_list_collections_example.py
['people', 'salaries']If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow