...

/

Create and Drop MongoDB Collections

Create and Drop MongoDB Collections

Learn and practice commands to create and drop a MongoDB collection.

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:

  1. Capped collection
  2. 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 collection, as listed ...