MongoDB Commands

To display all databases

> show dbs

Open existing or New database

use dbname

How to create a new database?

use newdb

Create a new collection

// create a collection

db.createCollection("myFirstCollection")

// collection with capped size

// The size: 2 means a limit of two megabytes, and max: 2 sets the maximum number of documents to two.

db.createCollection("mySecondCollection", {capped : true, size : 2, max : 2})

Display list of Collections

show collections
// drop database in MongoDB CE

db.dropDatabase()
// Drop database in MongoDB Atlas

use test;

db.runCommand({"dropDatabase":1})

Last updated