Cheatography
https://cheatography.com
Basic Mongo DB
|
Show name of current database |
|
Start database |
|
Connect to database |
|
Show databases |
|
|
|
Display current database collections |
Create
|
insert document(s) returns write result |
insertOne (data, options)
|
insert one document |
insertMany(data, options)
|
insert many documents |
insertMany([{},{},{}])
|
needs square brackets |
Read
db.collection.find()
|
Display documents from collection
|
|
find all matching documents |
findOne(filter, options)
|
find first matching document |
Update
updateOne(filter, data, options)
|
Change one document |
updateMany(filter, data, options)
|
Change many documents |
replaceOne(filter, data, options)
|
Replace document entirely |
Delete
deleteOne(filter, options)
|
Delete one document |
deleteMany(filter, options)
|
Delete many documents |
|
|
Filters
|
Used for filter arguments to filter collection |
{key: {$operator: value} }
|
Operators for querying data |
|
Matches all documents containing subdocument key
|
|
Matches values that are equal to a specified value. |
|
Matches values that are greater than a specified value. |
|
Matches values that are greater than or equal to a specified value. |
|
Matches any of the values specified in an array |
|
{key:{$in: [array of values] } }
|
|
Matches values that are less than a specified value. |
|
Matches values that are less than or equal to a specified value. |
|
Matches all values that are not equal to a specified value. |
|
Matches none of the values specified in an array. |
|
Performs AND operation |
|
|
{key: {$op: filter}, {filter}}
|
$and operator is necessary when the same field or operator has to be specified in multiple expressions |
find({doc.subdoc:value})
|
Filter sub documents |
Functions
|
Counts how many results |
|
Sort ascend:1 descend: -1 |
|
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets