Skip to content

Cheat sheet

Last updated on: 19 January, 2020
Compiled by: Evan Tay

The purpose of this page is to summarise key mongodb commands you will always use.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Select the database
show dbs
use <db-name> 

# Show all collections in the database
show collections 

# Print out all documents in the database
db.<collection-name>.find() 

# Print out in an easy-to-read but less compact format
db.<collection-name>.find().pretty()

Delete documents

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
show dbs
use <db-name> 

# Show all collections in the database
show collections 

# Remove all documents in the collection
db.<collection-name>.remove( { } )

# See reference for more information

Resources

Comments