• 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:
    1. Name- It represents the name of the collection and it is of string type.
    2. OptionsIt is an optional parameter.

Syntax:

This syntax specifies the following fields:

  1. Collection Name: It is used to create as capped collection.
  2. Capped: It is a Boolean field. If it is true, we create a capped collection.
  3. auto indexed: It is a Boolean flag and use for auto-indexing. Indexes will be created automatically, if the flag is true.
  4. Size: The maximum number of documents in bytes is represented by size. In context of capped collection, this is required field.
  5. Max: The highest number of documents that permit the collection was represented by max.

Categorized in: