MongoDB Cheat Sheet
by isaeus via cheatography.com/94031/cs/20684/
Basic Mongo DB Filters (cont)
db Show name of current database {key: Matches all documents containing subdoc‐
mongod Start database {$exists: ument key
true}}
mongo Connect to database
$eq Matches values that are equal to a specified
show dbs Show databases
value.
use db Switch to database db
$gt Matches values that are greater than a
show collections Display current database collections specified value.
$gte Matches values that are greater than or equal
Create
to a specified value.
insert(data) insert document(s) $in Matches any of the values specified in an array
returns write result
syntax: {key:{$in: [array of values] } }
insertOne (data, options) insert one document
$lt Matches values that are less than a specified
insertMany(data, options) insert many documents
value.
insertMany([{},{},{}]) needs square brackets $lte Matches values that are less than or equal to a
specified value.
Read
$ne Matches all values that are not equal to a
db.collectio‐ Display documents from specified value.
n.find() collection
$nin Matches none of the values specified in an
find(filter, options) find all matching documents array.
findOne(filter, find first matching document $and Performs AND operation
options) syntax: {$and: [ {},{} ] }
{key: {$op: $and operator is necessary when the same field
Update
filter}, or operator has to be specified in multiple
updateOne(filter, data, Change one document {filter}} expressions
options)
find({‐ Filter sub documents
updateMany(filter, data, Change many doc.subdo‐
options) documents c:value})
replaceOne(filter, data, Replace document
options) entirely Functions
.count() Counts how many results
Delete
.sort(filter) Sort ascend:1 descend: -1
deleteOne(filter, options) Delete one document
deleteMany(filter, Delete many documents
options)
Filters
{"key": "value"} Used for filter arguments to filter
collection
{key: {$operator: Operators for querying data
value} }
By isaeus Published 3rd October, 2019. Sponsored by Readable.com
cheatography.com/isaeus/ Last updated 3rd October, 2019. Measure your website readability!
Page 1 of 1. https://readable.com