MongoDB Management

Create a new database

use {databases-name}

Check current database

db

Show database

show dbs

The empty database won’t be displayed (at least one document is inserted)

In MongoDB default database is test. If you didn’t create any database, then collections will be stored in test database.

Drop database

db.dropDatabase()

Collections

Create a collection

db.createCollection("a-collection")

Show collections

show collections

Mongodb create a collection automatically when insert a document.

Drop collection

db.mycollection.drop()

Backup

mongodump -d {database-name} -o {dump-pass}

Restore for bson

mongorestore -d {database-name} -c {collection-name} {dump-pass}/{collection-name}.bson