Create and Drop MongoDB Collections
Explore how to create collections in MongoDB either implicitly or explicitly with custom options like capped and time series collections. Understand the commands to drop collections or delete documents selectively. This lesson helps you manage collections effectively using key MongoDB features.
We'll cover the following...
Create a collection
MongoDB implicitly creates a collection when a record is inserted or referenced in command for the first time. The implicit creation of a collection uses the default options.
We use the following command to create a collection.
db.createCollection(<name>, <options>);
MongoDB provides some special collections other than a normal collection. They’re listed below:
- Capped collection
- Time series collection
Capped collection
A capped collection limits the size and the maximum number of documents. If a capped collection reaches the maximum size or maximum number of documents, the older documents are removed. We require three additional options to create a capped ...