In the previous articles, we have created our "firstdatabase" and added the collection "Programming Languages" to the database. To print all the collection names in our database we will use the list_collection_names() method of the Database class.
Remember to initialize the MongoDB before running the script below:
col_name = 'Programming Languages' if col_name in mydb.list_collection_names(): print(True) else: print(False)
Once we add some data to our collection "Programming Languages", we will be able to see the name of the collection in the output. In the next article, we will insert "documents" i.e. records in our collection.
Comments