Skip to main content

Basic Commands

The following quick commands can be executed in the MongoDB shell. To do this, you must connect to the server or container and call the CLI with the correct authorizations:

mongo

List Databases

show dbs;

Use Database

use <yourdatabasename>;

List Collections

show collections;

Use Collection

use <yourcollectionname>;

Show all Entries

use <yourdatabasename>;
db.<yourcollectionname>.find();

Delete Database

use <yourdatabasename>;
db.dropDatabase();

Delete Collection

use <yourdatabasename>;
db.<yourcollectionname>.drop();

Insert Data

use <yourdatabasename>;
db.<yourcollectionname>.insertOne({"id":"123456789","name":"test","email":"test@test","password":"p49QSIBnEtJA3lD8kH5NYe"})

Duplicate Database

use <yourdatabasename>;
db.<yourcollectionname1>.find().forEach(function(d){ db.getSiblingDB('<yourcollectionname2>')['<yourcollectionname1>'].insert(d); });