MongoDB Cheatsheet

Connect from the local shell

mongo

Show all dbs

show dbs

Connect with a db

use DB-NAME

Show currently connected db

db

Show all collections

show collections

Show all entries of a collection

db.COLLECTION-NAME.find({})

Show all entries of a collection PRETTY

db.COLLECTION-NAME.find({}).pretty()

Update one entry

db.users.updateOne({"username":"Stn"}, {$set:{"username":"stn"}})

Update multiple entries

db.articles.updateMany({"status": "dismissed"}, {$set: {"status": "normal"}})

Delete one entry

db.users.deleteOne({"username":"test"})