MongoDB is an open-source document database and leading NoSQL database. MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License (SSPL).
Advantages of MongoDB
- MongoDB is free and open source software with a huge development community
- MongoDB’s query speed (find, update, insert, delete) is much faster than relational database management systems (RDBMS).
- The test shows that MongoDB’s insert speed can be up to 100 times faster than MySQL
Why is MongoDB so high performance? There are the following reasons:
- MongoDB stores data in JSON format, when you insert multiple objects, it will be inserting a JSON array almost like the case of inserting 1 object.
- Data in MongoDB does not have mutual constraints like in RDBMS, when inserting, deleting or updating it does not need to take time to check whether the related tables are satisfied as in RDBMS.
- Data in MongoDB is indexed, so when queried it will find it very quickly.
- When performing insert, find … MongoDB will lock other operations, for example when it performs find (), during the find process that insert, update, it will stop all to wait for find () to finish. is already.
- MongoDB is a document database, data is stored in JSON format, not bound by the number of fields, data types … you can freely insert the data you want.
The Rich Query Language:
- MongoDB is a rich query language which means it has built-in methods to create, read, update, delete data (CRUD).
- MongoDB supports replica set to ensure data backup and restore
- In MongoDB, there is a cluster concept that is a cluster of nodes containing data communicating with each other, when we want to expand the system, we only need to add a node with to the cluster:
Disadvantages of MongoDB
- MongoDB does not have the same binding properties as in RDBMS -> is susceptible to data corruption
- Joining is not supported like RDBMS, so when writing join function in code, we have to do it manually, making the query speed decrease.
- Use a lot of memory: Since the data is stored as key-value, the collections only differ in value so the key will be repeated. Joining is not supported, so there will be redundant data (in RDBMS, we only need to save 1 record and then refer to other records in MongoDB)
- Record size is limited: each document cannot be> 16Mb in size and no degree of child documents in a document can be> 100
MongoDB doesn’t support joins like a relational database. Yet one can use joins functionality by adding by coding it manually. But it may slow execution and affect performance.
When to use MongoDB
MongoDB is used for:
- Realtime system (real time) requires fast response
- Bigdata systems with fast query requirements.
- Systems with large write / insert frequencies
- Use as a search engine.