Brent Keller

MongoDB Cheatsheet

This is a simple reference so I can remember commands and syntax as I infrequently use MongoDB.

Mongo commands

show dbs
use <db>
show tables
db.<collection>.find()

Manipulating collections

db.<collection>.update({'title':'MongoDB Overview'},
   {$set:{'title':'New MongoDB Tutorial'}},{multi:true})

db.<collection>.deleteMany({}) # deletes all docs in collection
db.<collection>.deleteOne()

db.<collection>.update(
   { }, # all records in the collection
   { $set: { userId: null } }, # set the userId field
   { multi: true } # allows update of more than one document
)

Query syntax

# Filter by date: greater than
{"date": {$gte: new ISODate("2020-05-02")}}