Python Tutorials · Python MongoDB
MongoDB Collection
Learn all about MongoDB Collection in this comprehensive tutorial.
5 min read advanced
- •To create a collection in MongoDB, use database object and specify the name of the collection you want to create.
- •You can check if a collection exist in a database by listing all collections:
Introduction
Note: A collection in MongoDB is the same as a table in SQL databases.
Creating a Collection
To create a collection in MongoDB, use database object and specify the name of the collection you want to create.
MongoDB will create the collection if it does not exist.
python
Note: Important: In MongoDB, a collection is not created until it
gets content!
MongoDB waits until you have inserted a document before it actually creates the collection.
Check if Collection Exists
Note: Remember: In MongoDB, a collection is not created until it
gets content, so if this is your first time creating a collection, you should
complete the next chapter (create document) before
you check if the collection exists!
You can check if a collection exist in a database by listing all collections:
python
Or you can check a specific collection by name:
python
Module quiz
2 questions1
Which of the following is true about MongoDB Collection?
2
What is the most common pitfall when working with MongoDB Collection?
Answer all questions to submit.