0% found this document useful (0 votes)
15 views1 page

MongoDB Cheat Sheet

This MongoDB cheat sheet provides essential commands for managing databases, collections, and documents, including creating, updating, and deleting operations. It also outlines data types, sorting, limiting, and filtering options. Additionally, it covers comparison and logical operators for querying data effectively.

Uploaded by

Nandikaa Ganesh
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)
15 views1 page

MongoDB Cheat Sheet

This MongoDB cheat sheet provides essential commands for managing databases, collections, and documents, including creating, updating, and deleting operations. It also outlines data types, sorting, limiting, and filtering options. Additionally, it covers comparison and logical operators for querying data effectively.

Uploaded by

Nandikaa Ganesh
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

***********************************************************************************
Show the existing DATA TYPES: {$exists:true/false}},
databases: {update})
$ show dbs UTF-8 -----------------------
String encoded text DELETE:
Show the existing data Drop a database:
collections: 32-bit or $ db.dropDatabase()
$ show collections Integer 64-bit Note: To drop a
----------------------- integer database, you must be
CREATE: 64-bit in it.
Use a database: Double floating
$ use `db_name` point
Remove a field from
true or
Create a new db: Boolean doc:
false
$ use `new_db_name` $ db.col_name
Embedded
Object .updateOne({filter},
Note: After creating documents
{update})
a DB, it won't appear Lists of
Array
in `show dbs` until values filter={key1:val1,..,key
something is 12-byte
n:valn}
ObjectId unique
inserted.
identifier update={$unset:{key1:va
Milliseconds l1,..,keyn:valn}}
Create a collection: Date since Unix
$ db.createCollection epoch
(“name”) Remove a record from
Represents single doc:
----------------------- null
null value $ db.col_name.deleteOne
FIND:
----------------------- (filter)
$ db.col_name.find
INSERT:
({query}, {projection})
Insert a single record: Remove a record from
$ db.col_name.insertOne all doc:
Display all docx:
({key1:val1,key2:val2 $ db.col_name
$ db.col_name.find()
,..., keyn:valn}) .deleteMany (filter)
Display with filter:
Insert multiple Remove a record if a
$ db.col_name.find
({key1:val1,..,keyn:valn})
records: field exists/does not:
$db.col_name.insertMany $ db.col_name
Display selected fields: ([{key1:val1 ,..., .deleteMany
$ db.col_name.find({}, keyn:valn}, {key1:val1 ({key:{$exists:
{key1:true,..,keyn:true}) ,..., keyn:valn},..., true/false}})
{key1:val1 ,...,
Check if a field keyn:valn}]) filter={key1:val1,..,key
exists/does not: ----------------------- n:valn}
$ db.col_name.find UPDATE: -----------------------
({key:{$exists: Update/Add new field in COMPARISON OPERATORS:
true/false}}) first hitting doc: $eq $ne
----------------------- $ db.col_name $gt $lt
SORTING: .updateOne(filter, $gte $lte
Ascending order: update) $in $nin
$ db.col_name.find() $in: Matches any of
.sort({attr_name:1}) filter={key1:val1,..,key
the values specified
n:valn}
in an array.
Descending order: -----------------------
$ db.col_name.find() update={$set:{key1:val1,
LOGICAL OPERATORS:
.sort({attr_name:-1}) ..,keyn:valn}}
$and $not
-----------------------
Update/Add new field in $or $nor
LIMIT:
$ db.col_name.find() all doc: -----------------------
.limit(+ve #num) $ db.col_name
----------------------- .updateMany({filter},
SKIP DOCUMENTS: {update})
$ db.col_name.find()
.skip(+ve #num) Update if a field
----------------------- exists / does not:
$ db.col_name
.updateMany({key:

You might also like