Intro to MongoDB

DZone 's Guide to

Intro to MongoDB

In this article, see an introduction to MongoDB and look at the architecture and features.

· Database Zone ·
Free Resource

The word “database” instantly creates a picture of a table having rows and columns. Typically, any system architecture has a relational database management system (RDBMS) to store data. Data in an RDBMS is stored in tables containing rows and columns, and tables are connected to each other via relational models.

Examples of traditional RDBMSs include Oracle, MySQL, Microsoft SQL Server, DB2, etc. These databases have been in the market for a substantial amount of time, as they are highly efficient and deliver great performance.

However, an alternative to the conventional RDBMS that is trending in the market is NoSQL. NoSQL, which means “Not Only SQL”, is a database that stores data in non-tabular forms like document stores, graph DB, BigTable, etc. One of the leading examples of NoSQL is MongoDB.

This article will assist you with an intro to MongoDB, architecture, features, and why has it achieved huge popularity.

You might also want to read:  Getting Started With MongoDB


  • MongoDB is an open source, cross-platform, document-oriented NoSQL database that stores data in the form of documents and collections. A 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.

Image source: educba.com

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.


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


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.


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 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.


With MongoDB introduction as a chief NoSQL database, developers are expressing increased interest in it because of its varied features as discussed above. However, there are a couple of drawbacks to MongoDB as well, which doesn’t make it appropriate for all kinds of applications.

In the end, it is the developer’s responsibility to decide which database to be used by studying the project thoroughly and understanding if MongoDB is applicable or not.

Further Reading

Beginner’s Walkthrough: MongoDB and Java

MongoDB: The Basics

mongodb tutorial ,database ,intro to mongodb ,mongodb ,nosql ,nosql database

Published at DZone with permission of Sajan Agrawal . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}