Listing databases and collections
Our MongoClient
object is not actually a dictionary, so we can't call keys()
to list the names of accessible databases. The same is true for listing collections of a database. Instead, we can list database names by calling .list_database_names()
on a client instance, and we can list collection names by calling .list_collection_names()
on a database instance.
Este exercício faz parte do curso
Introduction to MongoDB in Python
Instruções do exercício
- Save a list, called
db_names
, of the names of the databases managed by our connectedclient
. - Similarly, save a list, called
nobel_coll_names
, of the names of the collections managed by the "nobel" database.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Save a list of names of the databases managed by client
db_names = client.____()
print(db_names)
# Save a list of names of the collections managed by the "nobel" database
nobel_coll_names = client.____.____()
print(nobel_coll_names)