The MongoDB
CheatSheet
By JavaScript Mastery
Connect MongoDB Shell
Connects to
mongodb://127.0.0.1:27017 by default
Connect to local network
Connect to MongoDB Atlas
Database Operation
Show All Databases
Show Current Database
Create / Switch to new Database
Database Operation
Delete Database
Collections
Show all collections of current DB
Create new Collection
Create Documents
Insert one document
Create Documents
Insert multiple document
Read Documents
Find one document
Find multiple documents
Find Multiple documents with json
Read Documents
Find documents by field value
Find By Element in Array
Update Documents
Update one
Update Multiple
Update Documents
Increment Field Value
Rename Field
Update Documents
Update Sub-Documents
Delete Documents
Delete a document
Count
Returns the count of documents
Returns the count of documents
that would match a find() query
Sorting
Ascending order
Descending order
Results by Pagination
Skip 7 results
Fetch only 4 results
Results by Pagination
Sort by name , Skip first 7 results,
fetch only next 4 documents
Add Index
Create Index on single field
Create compound Index
Drop Index
Drop Index
Text Search
Create Text Index on field
Search by Text
Find by range query
find courses where views are
greater than 70
find courses where views are
greater than or equal to 70
Find by range query
find courses where views are less
than 70
find courses where views are less
than or equal to 70
That’s it!
That’s it for this cheatsheet, there are many
more commands out there you can learn more
on mongodb’s official documentation.
Thank you so much. ️
Thank You for your Attention, Subscribe to my YouTube
Channel for more Advanced Tutorials.
- JavaScript Mastery
jsmasterypro javascriptmastery