Mongodb Cheetsheet

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

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 collec​tions Display current database collec​tions 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
insert​Man​y(data, options) insert many documents
value.
insert​Man​y([​{},​{},{}]) 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.co​​lle​​ct​i​o​‐ Display documents from specified value.
n.f​​ind() collection
$nin Matches none of the values specified in an
find(f​ilter, options) find all matching documents array.

findOn​e(f​ilter, 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
update​One​(fi​lter, data, Change one document {filter}} expres​sions
options)
find({​‐ Filter sub documents
update​Man​y(f​ilter, data, Change many doc.su​bdo​‐
options) documents c:v​alue})
replac​eOn​e(f​ilter, data, Replace document
options) entirely Functions

.count() Counts how many results


Delete
.sort(​filter) Sort ascend:1 descend: -1
delete​One​(fi​lter, options) Delete one document

delete​Man​y(f​ilter, Delete many documents


options)

Filters

{"ke​y": "​val​ue"} Used for filter arguments to filter


collection
{key: {$oper​ator: 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

You might also like