[go: up one dir, main page]

0% found this document useful (0 votes)
88 views23 pages

MongoDB CheatSheet 2022

This document provides a summary of common MongoDB commands organized into sections on connecting to MongoDB, database operations, collections, creating/reading/updating/deleting documents, counting, sorting, pagination, indexing, and text searching. It concludes by thanking the reader and encouraging them to subscribe to the author's YouTube channel for more advanced tutorials.
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)
88 views23 pages

MongoDB CheatSheet 2022

This document provides a summary of common MongoDB commands organized into sections on connecting to MongoDB, database operations, collections, creating/reading/updating/deleting documents, counting, sorting, pagination, indexing, and text searching. It concludes by thanking the reader and encouraging them to subscribe to the author's YouTube channel for more advanced tutorials.
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/ 23

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

You might also like