MongoDB Collections

A Collection in MongoDB is similar to a table in RDBMS. MongoDB collections do not enforce schemas. Each MongoDB collection can have multiple documents. A document is equivalent to row in a table in RDBMS.
Create Collection
To create a collection, use the db.createCollection()
command. The following creates a new employees
collection in the current selected database.

Above, the employees
collection is created using the creatCollection()
method. It returns an object { ok: 1 }
, which indicates the collection was created successfully.
As mentioned above, a single database can have multiple collections. The following creates multiple collections.

Display all Collections
Use the show collections
commands to list all the collections in a database.

Delete MongoDB Collection
To delete a collection, use the db.<collection-name>.drop()
method.

Average Rating