MongoDB can be used for 14 reasons: 1. High scalability by Sharding, 2. High Availability by Replication, 3. Schema free, 4. Indexing – secondary indexing, 5. Aggregation Framework, 6. Ad-hoc query, 7. File Storage, 8. BSON format, 9. Capped Collection, 10. Strong Active community, 11. Commercial & Community support, 12. Support of client Drivers , 13. Admin utility tools. These are the strong reason to use MongoDB in your all applications.
1. High scalability by Sharding
First of all, understand the concept of Sharding. Sharding is partitioning of data and placing it on multiple nodes/machines in such a way so that order of the data is preserved and accept read and write request. NoSQL database such as MongoDB uses sharding for horizontal scaling or you can say for scale-out your MongoDB database.
Vertical scaling means adding more resources (CPU, RAM, disk etc) to the existing machine while horizontal scaling means adding more machines to handle the more data either for ‘size of data’ or for ‘volume of data’. From DBEngine implementation point of view, Vertical scaling is easy simply adding of data but from DBA ( who manages of Data) that easy to implement, on the other hand horizontal scaling is easy to implement. Horizontal scaling database examples: MongoDB, Cassandra etc. Because of this feature NoSQL can handle a huge amount of data, as the data grows NoSQL scale itself to handle that data in an efficient manner.
2. High Availability by Replication
Auto replication feature in MongoDB makes it highly available because in case of any node failed, still replica set will be available. Usually, we make replica set of MongoDB with 3 nodes and in case of one node goes down, replica set will be available with 2 nodes to accept for read and write.
3. Schema free
MongoDB does not have restriction on schema of database, however, you can add restriction or validation on it, if you want but that is not preferable. Just because of dynamic schema it gain popularity. It means developer love to use of schemaless structure, it means, in first document you can add 2 column and in second document you can add 5 columns/keys. This gives you flexibility to change your data in schema without modifying any of your existing data without DBA involvement.
A Schema-less database means one collection can hold different types of documents in it. Or in other words, in the MongoDB database, a single collection can hold multiple documents and these documents may consist of the different numbers of fields, content, and size. It is not necessary that the one document is similar to another document like in the relational databases. Due to this cool feature, MongoDB provides great flexibility to databases.
4. Indexing – secondary indexing
Secondary indexing is one of the great feature which MongoDB provide us. we can add the data in JSON structure and later point of time we can get request. We need secondary index on a particular keys you can make index on it, specially size of the data is very huge.
- to get the response faster
- to reduce the no of IOPS on disk i.e. collection scan
- utilize the resource of server to optimize the throughput
5. Aggregation Framework
MongoDB does not support join directly but it support via aggregation framework. In any database aggregation is costly operation and so in MongoDB too. It allows to perform operations on the grouped data and get a single result or computed result. It is similar to the SQL GROUP BY clause. It provides three different aggregations e.g.:
- aggregation pipeline
- map-reduce function, and
- single-purpose aggregation methods
6. Ad-hoc Query
Ad-hoc query is the query which is not known while designing or structuring the database. MongoDB provides ad-hoc query support which makes it so special to developer or admin of MongoDB.
The biggest advantage of MongoDB over other databases is its performance under pressure especially when handling ad-hoc queries on data that are usually updated in real time. MongoDB can retrieve specific fields, ranges, locations, values, and even respond well to regular expression queries.
7. File Storage
MongoDB support all types of file storage, whether it is big or small. if document size is up to 16 mb keep data as byte or byte in normal document. if file size is greater than 16 MB then keep data in GridFS (Grid File Storage). GridFS has the capability to store file even greater than its document size limit of 16MB.
Storing of file in mongoDB is more secure than that storing of file in normal folder. you can store any secure document or any document like pdf, word, image, video etc.
8. BSON Format
MongoDB stores all documents as BSON, which is just a binary encoding of the good old JSON format. When store JSON data in mongoDB it store as BSON (Binary JSON). when it traverse the data over the network then it traverse in BSON (Binary JSON). JSON has UTF-8 encoding while BSON has binary encoding. BSON is readable by machine only while JSON is readable by Human and machine both.
9. Capped Collection
Capped collections are fixed-size collections that support high-throughput operations that insert and retrieve documents based on insertion order. Capped collections work in a way similar to circular buffers: once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection. It means it replace new one document with older one if the document is full.
we have to create the size of the collection and tell the MongoDB engine, hey MongoDB engine this is my capped collection.
10. Strong Active community
There is large ecosystem of user of MongoDB. initially it was developed for log only but later point of time it gain momentum and being used by all type of application and all type of companies. There are so many banking and financial system where MongoDB used extensively.
11. Commercial and Community support
MongoDB has commercial support too along with community support. There are so many companies providing their platform to use MongoDB as SaaS (Software as a Service), even MongoDB too offers this type of offering to ease out of the use.
MongoDB has a community edition of the software of the MongoDB database. It means a user of the MongoDB does not have to pay a single penny on subscription or licensing fee for deploying MongoDB community edition database.
12. Support of client drivers
MongoDB provides drivers of almost all the programming languages to connect to MongoDB to pull the data or push the data.
You can start using MongoDB with your own preferred language. The list on official site as: MongoDB https://docs.mongodb.com/drivers/
13. Admin Utilities tools
There are a lot of MongoDB monitoring utility tools for different admin jobs which is absolutely free. the few name as: mongodump for taking a dump, mongorestore for restoring of BSON data taken dump on another machine or same machine. mongoexport and mongoimport for exporting and importing of data in different formats.
You reach here, it means you like this post. Please share this post and write you comment to encourage me to post like this. Happy Learning 🙂