KEMBAR78
MongoDB Quick Reference Guide | PDF | Data | Computer Science
0% found this document useful (0 votes)
76 views1 page

MongoDB Quick Reference Guide

This cheat sheet provides a concise summary of basic MongoDB commands and operations. It outlines commands for connecting to and switching between databases, viewing and creating collections, and inserting, finding, updating, replacing, and deleting documents. It also summarizes common query operators like $eq, $gt, $lt, and $in for filtering documents based on field values. Functions like .count() and .sort() are mentioned for counting and sorting query results.

Uploaded by

avinash738797
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views1 page

MongoDB Quick Reference Guide

This cheat sheet provides a concise summary of basic MongoDB commands and operations. It outlines commands for connecting to and switching between databases, viewing and creating collections, and inserting, finding, updating, replacing, and deleting documents. It also summarizes common query operators like $eq, $gt, $lt, and $in for filtering documents based on field values. Functions like .count() and .sort() are mentioned for counting and sorting query results.

Uploaded by

avinash738797
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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