DEV Community

Cover image for All MongoDB commands you need to know

All MongoDB commands you need to know

Madhu Saini on April 05, 2024

Introduction Welcome to the world of MongoDB! If you're new to databases and want to learn how to manage them effectively, you're in the...
Collapse
 
gorhovakimyan profile image
gorhovakimyan2001 •

Hi all, there are also other MongoDb commands that can be useful

Indexing Commands:
Creating an Index: db.collection.createIndex({ field: 1 })
Viewing Indexes: db.collection.getIndexes()
Dropping an Index: db.collection.dropIndex("index_name")

Aggregation Commands:
Aggregation Pipeline: db.collection.aggregate([pipeline])
Grouping Documents: $group
Filtering Documents: $match
Projecting Fields: $project
Sorting Documents: $sort

Backup and Restore Commands:
Exporting Data: mongoexport
Importing Data: mongoimport
Database Dump: mongodump
Database Restore: mongorestore

Collapse
 
madhusaini22 profile image
Madhu Saini •

Thanks for sharing!!

Collapse
 
pavelee profile image
Paweł Ciosek •

Tank you! 👏👏

Collapse
 
madhusaini22 profile image
Madhu Saini •

My pleasuee

Collapse
 
prsaya profile image
Prasad Saya •

Here is a useful one: db.version(). This shows the version of the database server you are connected to.

Collapse
 
madhusaini22 profile image
Madhu Saini •

Wow, I wasn't aware of this command. Thank you so much for sharing, Prasad!!

Collapse
 
ronakjain2012 profile image
Ronak Bokaria •

creating DB users is also important when you move to prod DB

Collapse
 
madhusaini22 profile image
Madhu Saini •

True that

Collapse
 
sh20raj profile image
Sh Raj •

Prisma ORM is better I think 🤔

Collapse
 
madhusaini22 profile image
Madhu Saini •

No Doubt it's better, but still many people use MongoDB and it's better to use mongo itself for simpler project and dbs

Collapse
 
jonnydev profile image
Jonathan •

Thank you!

Collapse
 
skipperhoa profile image
Hòa Nguyễn Coder •

Thanks you,. I hope you will soon write a tutorial on connecting mongodb + Nodejs

Collapse
 
madhusaini22 profile image
Madhu Saini •

Gonna write that soon,

Thank you so much for the feedback :)

Collapse
 
cheikhnouha profile image
Cheikhnouha •

Great to job

Collapse
 
rohiitbagal profile image
Rohit •

Very useful....and existing information....

Collapse
 
madhusaini22 profile image
Madhu Saini •

Thanks Rohit!

Collapse
 
jangelodev profile image
João Angelo •

Hi Madhu Saini,
Your tips are very useful
Thanks for sharing

Collapse
 
madhusaini22 profile image
Madhu Saini •

Thanks :)

Collapse
 
lucaschitolina profile image
Lucas Chitolina •

Thanks for that, always good to remember some commands and learn new ones. Great post!

Collapse
 
madhusaini22 profile image
Madhu Saini •

Glad it helped, Thanks for the feedback Lucas

Collapse
 
thatanjan profile image
Anjan Shomodder •

I don't even remember when I last used db commands. I always use mongoose. but nice post though

Collapse
 
madhusaini22 profile image
Madhu Saini •

Hope it refreshed your commands, Thanks Anjan :)

Collapse
 
epicurus1 profile image
epicurus •

Wow really helpful.

Collapse
 
madhusaini22 profile image
Madhu Saini •

Glad it helped, Thanks for the feedback :)

Collapse
 
ajay8086 profile image
Ajay-8086 •

Thank you

Collapse
 
testybryan profile image
Testy Bryan •

Thanks alot

Collapse
 
vargass7 profile image
Sandro •

Useful material, thanks !

Collapse
 
madhusaini22 profile image
Madhu Saini •

Thanks Sandro :)

Collapse
 
grooms_nicholas profile image
Zack Grooms •

Thanks for the helpful insights, Madhu. I was planning to use MongoDB for a client, and this was well put together.

Collapse
 
madhusaini22 profile image
Madhu Saini •

Awesome!

Glad it helped, Thanks for the feedback Zack!

All the best for your next project :)

Some comments have been hidden by the post's author - find out more