What is the use of Capped Collection 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 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.
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like

MongoDB Vs CouchDB

                MongoDB                  CouchDB It Provides faster read speeds. If read speed is critical to your database, MongoDB is faster than CouchDB. No mobile support provided. It can be run…
View Answer

What are the Features of MongoDB ?

It has so many great features while being a NoSQL database. It is unique and attractive. They are making MongoDB widely usable and popular. Features of MongoDB: Schema-less Database Replication…
View Answer