What is MongoDB ?

MongoDB is a NoSQL database which is document-oriented and is used for high volume data storage. MongoDB makes use of collections and documents, instead of using tables and rows as in the relational databases. Documents contain key-value pairs which are considered as the basic unit of data in MongoDB. Collections consists of set of documents and function which is the equivalent of relational database tables.

  • In MongoDB, each of the database consists of collections which in turn comprises of documents. Each document might be different with a varying number of fields. The size and content of each document can be different from each other.
  • The document structure is more specific to how developers construct their classes and objects in their respective programming languages. Developers will often say that their classes have a clear structure with the different key-value pairs.
  • The documents in MongoDB does not need to have a schema defined beforehand. Instead, the fields can be created instantly.
  • With MongoDB, it is possible to represent hierarchical relationships, to store arrays, and other more complex structures more easily.

How it works ?

Now, we are aware that MongoDB is a database server and the data is stored in these databases. MongoDB environment basically provides the users with a server that they can start and then create multiple databases on it using MongoDB.

Because of its NoSQL database, the data is stored in the collections and documents. Hence the database, collection, and documents are related to each other as shown below:

  • The MongoDB database contains collections just like the MYSQL database contains tables. The users may create multiple databases and multiple collections.
  • Inside the collections, documents are present which contain the data we want to store in the MongoDB database and a single collection can contain multiple documents and we are schema-less means it is not necessary that one document is similar to another.
  • The documents are created using the fields that are key-value pairs in the documents, it is just like columns in the relation database. The value of the fields can be of any BSON data types like double, string, boolean, etc.
  • The data is stored in the MongoDB in the format of BSON documents. The BSON stands for Binary representation of JSON documents. The MongoDB server converts the JSON data into a binary form that is known as BSON and it is stored and queried more efficiently.
  • MongoDB also allows the users to store nested data which allows to create complex relations between data and store them in the same document which makes the working and fetching of data extremely efficient as compared to SQL. In case of SQL, users need to write complex joins to get the data from table 1 and table 2. The maximum size of the BSON document can be 16MB.

Features of MongoDB

  • Document Oriented: MongoDB stores all the data in the form of documents instead of tables like in RDBMS. In these documents, the data is stored in key-value pairs instead of rows and columns which make the data much more flexible in comparison to RDBMS where each documents contains a unique ID.
  • Schema-less Database: Schema-less database is a great feature provided by MongoDB which means one collection can hold different types of documents in it. 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 required that a document is similar to another document as it is in the case of relational databases. Due to this amazing feature, MongoDB provides great flexibility to databases.
  • Scalability: MongoDB provides horizontal scalability with the help of a mechanism known as sharding. Sharding refers to the process of distributing data on multiple servers, here a large amount of data is partitioned into data chunks using the shard key, and these data chunks are evenly distributed across shards that reside across many physical servers. It can also add new machines to a running database.
  • Indexing: MongoDB database indexes every field in the documents with primary and secondary indices which makes it easier and takes less time to get or search data from the pool of the data. If the data is not indexed, then database search each document with the specified query which takes lots of time and not so efficient.
  • Aggregation: MongoDB also allows to perform operations on the grouped data and get a single result or computed result. It provides three different aggregations, namely, aggregation pipeline, map-reduce function, and single-purpose aggregation methods.
  • High Performance: Due to its features like scalability, indexing, replication, etc., the performance of MongoDB becomes very high and also data persistence as compared to any other databases.

Advantages of MongoDB

  • It is a schema-less NoSQL database. Therefore, we need not to design the schema of the database when we are working with MongoDB.
  • It is a document oriented database and the data is stored in BSON documents.
  • It contains heterogeneous data.
  • It can be easily integrated with Big Data Hadoop.
  • It does not support join operation.
  • It provides extreme flexibility to the fields in the documents.
  • It provides high performance, availability, scalability.
  • It also supports multiple document ACID transition.
  • It does not require any SQL injection.

Summary

  • In this article we explored one of the most popular database systems in today's marketplace i.e., MongoDB. MongoDB is a NoSQL database which is document-oriented and is used for high volume data storage.
  • We understood how MongoDB operates in various points.
  • We learnt the various salient features of MongoDB like Flexibility, Scalability, Schema-less Structure and others that make it unique and dependable.
  • We also saw the multiple advantages of using MongoDB for our applications.