This is article 2 of 4 exploring each technology in the MERN stack:
To check out our overview of the stack and why it is so popular, you can see our article here. In these articles, we’ll go a bit deeper on each technology, their history, and even tease out what the future of each will hold.
Without further ado – here’s MongoDb!
Understanding MongoDB: A Digital Filing Cabinet
One of the key purposes of modern applications is to allow users to interact with information (data). Think about searching Amazon for the perfect pair of shoes, or finding the nearest Thai food restaurant on Google Maps. Amazon needs to store the data for their products, and Google needs to store a list of all restaurants. And when you make a purchase, the data showing what you purchased and where it needs to be sent needs to be recorded as well! Before modern computers, data like this was stored in things like ledgers, filing cabinets, or rolodexes. But now, we store this data in databases.
MongoDB is a type of database, which, like our filing cabinet, is used to store and manage data. But instead of paper, it stores digital data. It’s designed to handle large volumes of data and to retrieve this data quickly and efficiently, much like how an organized filing cabinet allows you to find what you need without rummaging through piles of paper.
Before MongoDB: Relational Database
Before MongoDB, most databases were known as “relational databases”, and could easily be visualized as a spreadsheet with rows and columns. You need to decide in advance how to organize your documents, and there’s not much room for change. Take the following data. This database was set up to hold information about a set of customers. When the database was created, it was determined that the 4 pieces of information that need to be tracked are ID, FirstName, LastName, and RegistrationDate.
If it were determined that the database also needs to track Alex Smith’s middle name, there would be no way to store that information without adding a whole new column. This is possible, but it is very inefficient because there would now be empty or “null” values in this column for every other customer.
Why MongoDB is Different
MongoDB, however, offers a more flexible approach. Rather than a spreadsheet, MongoDB is much more like the filing cabinet example with individual folders for each record.
Imagine a filing cabinet in a Doctor’s office. The files for long-time patients may contain dozens of documents, while files for newer patients only have one or two. This way of structuring your data is so much more flexible than trying to record all information in spreadsheets that must conform all the data into set columns.
Popularity of MongoDB: Why Many Prefer It
MongoDB has gained popularity for several reasons:
Flexibility: Unlike traditional databases that require strict organization, MongoDB allows for more flexible data storage. This means it can easily handle a wide variety of data types, which is great for modern applications that deal with diverse data sets.
Scalability: MongoDB can grow with your needs. Think of it as a filing cabinet that can be expanded as you add more documents. This makes it ideal for businesses that are scaling up and constantly accumulating more data.
User-Friendly: MongoDB is known for being relatively easy to use. It’s like having a filing cabinet with an intuitive labeling system, making it simpler to find what you need without extensive training.
Are there downsides?
- Data Size and Overhead: Like overstuffed folders, documents in MongoDB can become very large. This can lead to increased storage requirements and network overhead, particularly for applications with deeply nested documents or those that require frequent updates.
- Memory Usage: MongoDB relies heavily on system memory to store working sets, making it fast for operations that fit within the available memory. However, this can become a limitation for databases with large datasets that exceed the server’s memory capacity, potentially leading to performance degradation.
- Schema-less Nature: MongoDB does not force data into a particular schema (pattern), like a relational database does. While this allows for flexibility in storing unstructured data, it can also lead to data inconsistency and integrity issues. Without strict schemas, it’s easier to introduce errors and discrepancies into the database, which can complicate data retrieval and analysis.
The Future of MongoDB: Evolving with Technology
As technology continues to evolve, MongoDB is also adapting. It’s incorporating more features to handle not just more data, but also more complex types of data. The focus is on making data retrieval even faster and more efficient, akin to having a filing cabinet that not only organizes your documents but also suggests the fastest way to find what you’re looking for.
In conclusion, MongoDB stands out in the world of databases for its flexibility, scalability, and ease of use. It’s a powerful tool for managing modern data needs, much like an advanced, adaptable filing cabinet for the digital age.
Interested in learning more about how we can help you transform your life by learning how to code? Click below to get all of your questions answered.