Skip to main content

MongoDB Cheatsheet

Published on December 23, 2020

This document was migrated from DigiDocs

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

# 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

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