MongoDB

From CNM Wiki
Revision as of 12:51, 8 February 2020 by Gary (talk | contribs)
Jump to: navigation, search

MongoDB (hereinafter, DB) is open-source cross-platform document-oriented NoSQL database software that stores data in the form of documents and collections. DB can also refer to a database management system based on that software.

DB is developed by MongoDB Inc. and licensed under the Server Side Public License (SSPL). A couple of drawbacks don't make DB appropriate for all kinds of applications. Among DB users are the City of Chicago, Codecademy, Google Search, IBM, The Gap, Inc., Uber, Coinbase, Barclays, HSBC, eBay, Cisco, and Bosch.


Architecture

DB uses JSON-like documents with schema. The document is nothing but a record that contains all information about itself. A group of documents is called a collection.

   A document can contain a number of fields (value), regarding the details of the record. One document size can be different from the other as two different documents can store a varied number of fields. Every field (value) has an associated key mapped to it. The field can be of any data type like the general text, number, etc. A field can also be a link to another document or arrays. MongoDB uses BSON (binary encoding form of JSON), to include additional data types like date, that is not compatible with JSON.
   There is no forced relation between the fields, but links and data models can be established while creation. Data models facilitate the storage of arrays, establish hierarchical relations, etc.
   Data is stored in a stream, and not in a schema, unlike the RDBMS.
   Mongo DB provides a JavaScript interface called the Mongo shell, that is used for querying and creating documents.

If you compare it with an RDBMS, documents correspond to the record (row), which has a unique identifier ID (primary key), fields/values are columns that have an associated key to them, and collections are the equivalent of a table. Features

With MongoDB in the market, more and more developers are using it in specific applications due to its many benefits and advantages.

Scalability

MongoDB is a specialized database for Big Data processing. It can contain large volumes of data, making it highly scalable. It also supports the concept of horizontal scaling, where data can be distributed across multiple DB instances. This helps in data load balancing as well as duplication of data as a backup.

Flexibility

MongoDB is schema-less, which means it doesn’t enforce relations between fields, rather, it allows the storage of values of any data type in a stream. Since data is stored in a document/collection type of model, it offers flexibility in terms of data modeling and data alteration and updation on the fly without the hassle of schema updation like in an RDBMS.

Sharding

Sharding is an interesting and very powerful methodology in MongoDB. MongoDB allows the distribution of data onto several servers, as opposed to a single server. For applications having huge volumes of data, the load can be balanced by storing data in several servers. This also helps in increasing the capacity of the database as well as concurrent and parallel processing of tasks.

Data Replication and Recovery

MongoDB provides specialized tools for data replication as a backup, in times of any system failure. The main server, acting as the primary server, stores all the data and takes care of the read/write and other transactions. The secondary server is a replica of the primary server, which can take over and act as a primary server in case the primary server crashes or fails, thereby providing high availability all the time.

High Performance and Speed

MongoDB supports different features like dynamic ad-hoc querying, indexing for faster search functionality, tools like Aggregation pipeline for aggregation queries, etc. that help in faster processing. Querying is also quicker, as compared to an RDBMS, as related data are stored together in documents. This guarantees high performance, even in critical high volume situations.

MongoDB is a significant part of MEAN and MERN stack as their primary database for data storage. Written in JavaScript, it has easily blended with these stacks that are popular for building interactive and responsive web applications.

Apart from JavaScript, MongoDB is seamlessly compatible with several other programming languages like Ruby and Python as well, making it a sought-after NoSQL database.