Advantages of Capped Collections
- To return documents in insertion order, queries do not need an index, since it provides greater insertion throughput.
- Capped collections allow changes that match the size of the original document to ensure that the document does not change its position on the disk.
- Holding log files is useful.
Capped Collections in MongoDB
Capped collections are fixed-size collections means when we create the collection, we must fix the maximum size of the collection(in bytes) and the maximum number of documents that it can store. After creation, if we try to add more than documents to their capacity, it overwrites the existing documents. It supports high-throughput operations, that are useful when we insert and retrieve documents based on insertion order. The working of the capped collection is similar to circular buffers, which means once the fixed space is allocated for the capped collection, it creates/makes spaces for the new documents by overwriting the oldest documents in the given collection. Capped collection can also have _id field and by default, each _id field has an index.