Mongodb Cheat Sheet

As part of our MongoDB Guide, we’ve compiled this cheat sheet of common and not-so-common MongoDB commands.

(This article is part of our MongoDB Guide. Use the right-hand menu to navigate.)

Pretty Print
Create Collection
Create Indexes
Create index
Create sparse index
Create compound index
Create geo index
Create partial index
Add and Delete Data
Add one data record
Add array (many) records
Delete data
Query MongoDB Documents
Search by attribute
Search by geolocation
Search greater or less than
Search not equal to
Search and return only certain fields
Search by regular expression
Find by elements in array
Replication and Sharding
Enable replication
Add shard
Show Server Memory
Aggregate functions
MapReduce

Pretty Print

Add pretty() to the end of any search:

db.collection.find({}).pretty()

Create Collection

db.createCollection("<collection name>")
Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article