- Capped collections are fixed-size collections means when we create the collection, we must fix the maximum size of the collection (in bytes) and it can store the maximum number of documents.
- After creation, it overwrites the existing documents, when we try to add more than documents to their capacity.
- They are useful when we insert and retrieve documents based on insertion order, it supports high-throughput operations.
- It is similar to circular buffers, which means once the fixed space is allocated for the capped collection.
- Capped collection can also have _id field and by default, each _id field has an index.
- In this collection, there are two parameters:
-
- Name- It represents the name of the collection and it is of string type.
- Options–It is an optional parameter.
Syntax:
This syntax specifies the following fields:
- Collection Name: It is used to create as capped collection.
- Capped: It is a Boolean field. If it is true, we create a capped collection.
- auto indexed: It is a Boolean flag and use for auto-indexing. Indexes will be created automatically, if the flag is true.
- Size: The maximum number of documents in bytes is represented by size. In context of capped collection, this is required field.
- Max: The highest number of documents that permit the collection was represented by max.