DEV Community

Cover image for A-Z: MongoDB Cheat Sheet🌱

A-Z: MongoDB Cheat Sheet🌱

Burak Boduroğlu on June 20, 2023

New Post 🆕 Boost Your Programming Efficiency: Essential Tools for Success ⚙️ Building a Node.js Server Without Using Express.js🐤 Docker...
Collapse
 
imthedeveloper profile image
ImTheDeveloper

Nice overview. Loved mongo for very simple document storage where there is little to no need to do any complex joins. It can become a beast when needing to use the aggregation pipeline and transformations I've walked into that a couple of times now and wished I'd have stuck to something more relational. My own fault and lesson learnt 🤣 again though really nice overview and covers so many use cases.

Collapse
 
prsaya profile image
Prasad Saya

The document data of MongoDB is like JSON (plus has more types) and it includes complex types like objects and arrays, often nested to multiple levels (upto 100 levels is possible as per the docs). Working with these complex structures is not always easy. First, the aggregation pipeline syntax is unlike other database querying syntax and there is a learning curve. Attempting aggregation queries on complex data and complex operations without proper learning, the tools and experience is not uncommon - it can create disappointments.

Collapse
 
burakboduroglu profile image
Burak Boduroğlu

🤩🥳

Collapse
 
umakantv profile image
Umakant Vashishtha

This is helpful, I wrote a similar article:
umakantv.medium.com/mongodb-operat... with more types of operators and an example which demonstrates fuzzy text search.

Collapse
 
burakboduroglu profile image
Burak Boduroğlu

Thank you. It looks like helpful.😊

Collapse
 
michaeltharrington profile image
Michael Tharrington

Awesome post here, Burak! This is a really helpful and easy-to-read cheat sheet. 🙌

Collapse
 
burakboduroglu profile image
Burak Boduroğlu

I am happy to It was useful. Thank you. 🥳

Collapse
 
prsaya profile image
Prasad Saya

Good effort 👍.

I would also include the variations of update and delete methods updateMany and deleteMany. Also, countDocuments is useful.

One of the more useful features of using MongoDB is one can develop applications fast, as it allows quick start and prototyping (for example, I can write application code accessing the database and insert data, query it, etc., without creating a database or a collection, and fields explicitly).

Collapse
 
billernet profile image
Bill💡

Good stuff. We replaced our legacy XML based document format with MongoDB and saw massive speed improvements in loading and querying data. I'm a big proponent of dealing with documents with large volume/size/complexity this way. One thing I would take issue with though is this:

  • Why use MongoDB?

MongoDB is a document database, which means it stores data in JSON-like documents. We believe this is the most natural way to think about data, and is much more expressive and powerful than the traditional row/column model.

While yes, it probably does let you store data in exactly the format that represents the original document, I think it is worth stating that it shouldn't be seen as a wholesale replacement for relational databases. A good rule of thumb is if to use MongoDB or any other document database, and you're finding that the document is starting to contain items which are outside the natural scope of the document to get it to work, it is not a good fit.

Define boundaries for what is stored in the document and be aware of the limitations of relationships between documents.

Collapse
 
burakboduroglu profile image
Burak Boduroğlu

Thanks for sharing this nice comment.😊

Collapse
 
boly38 profile image
Brice

Good idea 👍🏻

Improvement idea:
From industrialization point of view
When I do update the mongo part of my application I check every possible queries from repository classes and check fields used to build indexes and avoid perf Issues.
You could maybe add a section about indexes and explain plans.

Collapse
 
burakboduroglu profile image
Burak Boduroğlu

Thanks for your recommendation. I’m going to add this section. 😇

Collapse
 
onlinemsr profile image
Raja MSR

Thank you for sharing this useful MongoDB cheat sheet. I found it very helpful and concise. It covers the most common commands and operations for working with MongoDB databases.

I appreciate your effort and time in creating this resource!

Collapse
 
burakboduroglu profile image
Burak Boduroğlu

👾👨🏻‍💻🙏🏼

Collapse
 
faisal00121 profile image
Cloudrcm Solutions

Great MongoDB cheat sheet! It's always helpful to have a quick reference guide to assist with common tasks and commands in MongoDB. As someone interested in cloud RCM (Revenue Cycle Management), I can see the potential benefits of integrating MongoDB into cloud-based RCM systems.

Collapse
 
burakboduroglu profile image
Burak Boduroğlu

Thanks for your comment.😊

Collapse
 
araaranomi profile image
Ara Ara no Mi

I still don't have any usecases for MongoDB, all the data I use ends up being Relational, and I prefer SQL's syntax.

Collapse
 
kumarkalyan profile image
Kumar Kalyan

Great reasource for mongo db :)

Collapse
 
burakboduroglu profile image
Burak Boduroğlu

Thank you :) 👾

Collapse
 
vulcanwm profile image
Medea

really helpful!

Collapse
 
burakboduroglu profile image
Burak Boduroğlu

I’m glad to hear that. 😄

Collapse
 
adeleyeayodeji profile image
Adeleye Ayodeji

Thank you for the information.

Collapse
 
shree675 profile image
Shreetesh M

This is a good sheet to get a hold on the fundamental commands and operations.

Collapse
 
burakboduroglu profile image
Burak Boduroğlu

😇

Collapse
 
layanyashoda profile image
Layan Yasoda

Awesome Post! Thank you.

Collapse
 
chiemelie profile image
Chiemelie

The cheat sheet would have gone in an ascending order. Starting with the very basic element in the cheat all the way to the hardest. It makes things easier to understand.