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

Manipulating collections

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

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

   { }, # 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")}}