Skip to content

Instantly share code, notes, and snippets.

@wooyey
Last active November 10, 2020 22:02
Show Gist options
  • Save wooyey/74ff7efbc6577e4e6f6fb72dc245e2da to your computer and use it in GitHub Desktop.
Save wooyey/74ff7efbc6577e4e6f6fb72dc245e2da to your computer and use it in GitHub Desktop.
Mongo Cheat Sheet

Login

use <db_name>
db.auth('user', 'pass')

Collections

show collections

Find

db.<collection>.find({"field.even.nested": "value"}).pretty()

Update

db.<collection>.updateOne({"filter.field": "value"}, { $set: { "field": "value1", "another.field": "value2" } })

Delete list of IDs

var ids = ['<id1>', '<id2>'];
var obj_ids = ids.map(function(id) { return ObjectId(id); });
db.<collection>.remove({_id: {$in: obj_ids}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment