Hello, in this tutorial we will see the pros and cons of using the MongoDB.
One of the top benefits offered by MongoDB is the use of dynamic schemas that eliminates the need to pre-define the structure, like fields or value types. Such model allows hierarchical relationships representation, array storage, and ability to change the records structure by simply adding or deleting fields.
This NoSQL solution comes with embedding, auto-sharding, and on-board replication for better scalability and high availability. General distributions for MongoDB support Windows, Linux, Mac OS X, and Solaris.
1.1 Terminology and Concepts
If you’re not familiar with MongoDB, here’s a quick translation cheat sheet to get you familiar with the terminology:
|Joining||Linking & Embedding|
|Partition||Sharding (Range Partition)|
1.2 Making the Choice
Of course, developer’s choice of database is always a decision based on pros and cons,
- Document oriented
- High performance
- High availability — Replication
- High scalability – Sharding
- Dynamic — No rigid schema
- Flexible – field addition/deletion have less or no impact on the application
- Heterogeneous Data
- No Joins
- Data Representation in JSON or BSON
- Geospatial support
- Easy Integration with BigData Hadoop
- Document-based query language that’s nearly as powerful as SQL
- Cloud distributions such as AWS, Microsoft, RedHat, dotCloud and SoftLayer etc. In fact, MongoDB is built for the cloud. Its native scale-out architecture, enabled by ‘sharding,’ aligns well with the horizontal scaling and agility afforded by cloud computing
- A downside of NoSQL is that most solutions are not as strongly ACID-compliant (Atomic, Consistency, Isolation, Durability) as the more well-established RDBMS systems
- Complex transaction
- No function or stored procedure exists where you can bind the logic
People often ask why MongoDB is so wildly popular. I tell them it’s a data structure thing.
- E-commerce product catalog
- Blogs and content management
- Real-time analytics and high-speed logging, caching, and high scalability
- Configuration management
- Maintaining location-based data — Geospatial data
- Mobile and social networking sites
- Evolving data requirements
- Loosely coupled objectives — the design may change by over time
Not so Good For
- Highly transactional systems or where the data model is designed up front
- Tightly coupled systems
1.4 When would MySQL be a better fit?
While most modern applications require a flexible, scalable system like MongoDB, there are use cases for which a relational database like MySQL would be better suited. Applications that require complex, multi-row transactions (E.g., a double-entry bookkeeping system) would be good examples. MongoDB is not a drop-in replacement for legacy applications built around the relational data model and SQL.
A concrete example would be the booking engine behind a travel reservation system, which also typically involves complex transactions. While the core booking engine might run on MySQL, those parts of the app that engage with users – serving up content, integrating with social networks, managing sessions – would be better placed in MongoDB.
1.5 Which database to use?
Comparing MongoDB speed vs. MySQL, developers note that the latter one lacks speed and experience difficulties with large data volumes, so it’ll be a better choice for companies with smaller databases and looking for a more general solution. While this is one of the advantages of MongoDB over MySQL, the ability to cope with large and unstructured amounts of data.
To answer the main question: when to use MongoDB instead of MySQL? MySQL is well-recognized for its high performance, flexibility, reliable data protection, high availability, and management ease. Proper data indexing can solve the issue with performance, facilitate interaction and ensure robustness. But if application’s data is unstructured and complex, or if developers can’t pre-define the application schema, developers would better opt for MongoDB.
Hope this helped!
And, there you have it! Now, you’ve got a quick and easy overview of how MongoDB works, some use cases where it can shine, and how it relates to SQL technology.