Introduction To MongoDB - Part One

In this article, we will discuss the design and process of installing MongoDB to implement the structure of the data and related configuration of a MongoDB database.

If we talk about the core of most large and scalable applications or services, the best solutions always are the high-performance data storage solutions. So, every good application always requires the proper process or mechanism to store and retrieve data with accuracy, speed, and reliability. So, for the solution to this problem, there are several storage solutions available in the market which we can use. Out of them, the three main components are –
  1. Direct file systems in files
  2. RDBMS or Relational Database
  3. No SQL Database

The below sections describe the basic concept of NoSQL and MongoDB.

What is No-SQL Database? 

The actual meaning of NoSQL database is Not Only SQL. It means that NoSQL databases are actually an alternative to SQL Databases and can perform all types of query operations like Microsoft SQL Server. NoSQL contains all databases which are not a part of the traditional database management systems (RDBMS). The main objectives behind the NoSQL database are basically simple design, both horizontal and vertical scaling, and also easy control over the available data. NoSQL database breaks the traditional structure of the relational database for the first time and also provide developers such an opportunity where they can implement models just like data as per their programming requirements. This means that NoSQL databases can be implemented and designed in such a way that traditional relational databases could not be structured.

In today’s development world, there are several different NoSQL database technologies, like HBase Column structure, the Redis key/value structure etc. In this article series, we will discuss MongoDB since it is the most popular and well supported NoSQL database currently available. There are four types of NoSQL databases available currently:

  • Document Databases
    Document databases always apply a document-oriented approach to store data. The main idea behind this type of database is that all data for a single entity needs to be stored as a document and all documents can be stored together within a collection. This document can store the sub-document data, which in RDBMS are typically stored as an encoded string or within a separate table. Each and every document can be accessed by a unique key.

  • Key-Value Database
    In the NoSQL database category, key-value storage is the simplest one. These databases store the data in a schemeless way. A key can point to any type of data, like an object, string or any other types of data. The main advantages of these databases is they are easy to implement and add data into. Data can be fetched from these databases with the help of a key value. But the main drawback is that we can’t find any elements based on the stored value. We always need to find data on the basis of the key name.

  • Column Store Database
    These types of databases store data in columns within a keyspace. The key space is always defined on a unique name, value, and a timestamp. This is quite similar to key-value databases.

  • Graph Store Database
    These types of databases are mainly designed for data that can be easily represented as a graph data. This means that data are interconnected with an undetermined number of data relations between them like family and social relations, etc.

What is Document Database?

A document database is a special kind of database which is based on the principle of dealing with data or documents rather than strictly defined tables of information. These types of databases always play an important role in aggregating data from documents and getting them into a searchable, organized form.

In the document-oriented database, the concept of Row is replaced with the more flexible data model called documents. In this type, the database allows embedded documents and arrays in such a way that the document-oriented approach represents the more complex hierarchical data relationships in a single record. Basically, the document database always supports the semi-structured data model. For example, suppose one document has two names, one address, and a list of the ages of a home’s occupants. A second document might have four names, two addresses, and no age information. A document-oriented database will take the data in both and store them according to type, able to handle non-fixed length data sets. 

Advantages of Document Database over RDBMS

The main advantages of document-based databases are,

  1. It can store large volumes of structured, semi-structured, or unstructured data
  2. Each document in a collection is independent with respect to the other documents in the same collections
  3. The logic of the application is easy to write since there is no need for conversation of objects between database and applications like SQL database.
  4. It supports strong indexing features. For this reason, searching of the data is very fast.

Key Features of MongoDB

MongoDB is not only a general-purpose database which can perform only insert, update and delete data within it. Besides these, there are several important features which make the MongoDB one of the most popular and enriched databases in the world of NoSQL databases. Some of the features are as below,

  1. MongoDB supports JSON data models with dynamic schemas.
  2. In MongoDB, we can perform a search on any field or any range query and also can use a regular expression for searching the data
  3. MongoDB supports secondary indexes which allow us to search a variety of data in a very small timespan. It also provides us with different types of indexes like unique index, compound index, geospatial index etc.
  4. MongoDB supports aggregation pipeline which helps us to build complex aggregations to optimize the database
  5. MongoDB supports Master-Slave replication
  6. MongoDB support automatic load balancing features.
  7. MongoDB supports auto-sharding for horizontal scaling.
  8. MongoDB can store any type of file which can be any size without affecting our stack
  9. MongoDB basically use JavaScript objects in place of the procedure.
  10. MongoDB supports special collection type like TTL (Time-To-Live) for data storage which expires at a certain time.

Why & where do we need to use Mongo DB?

In a normal scenario, MongoDB is always preferred by the developers or project managers when they need to fulfill high insert rates of the data into the database with a high performance. If we need to load or save thousands of data with a low cost then MongoDB is one of the best choices for us. Also, if we need to partition and shard the database, then MongoDB also has an inbuilt solution for that. Also, horizontal scaling (adding new columns) is not very easy in the case of RDBMS systems. But in the case of MongoDB, since it is a schema-less database, adding new fields or removing existing ones is not so tough to do. Also, one important thing is that for adding or removing columns we do not require any Database Administrator or DBA in case of MongoDB. It automatically changes the schema structure when the application changes. Also, if you don’t want to normalize your data or don’t want to use joins for fetching data, then MongoDB is the perfect choice for you.

Perquisites of Mongo DB

MongoDB supports all types of operating systems. MongoDB is available in two versions – Community Server Edition (Perfect of Self Use or Developer Mode) and Enterprise Server Edition (For Business Purpose Use with Proper Licensing). The MongoDB installer is available for all types of operating systems like Windows, Linux or Mac OS. Installer for MongoDB can be downloaded from the MongoDB sites –

Introduction to MongoDB

How to Install Mongo DB

After downloading the MongoDB installer msi as mentioned in the above section, we need to run the installer.

Step 1

 Introduction to MongoDB

Now, click on the Next button and complete the Installation Features and then click "Next".

Step 2

Introduction to MongoDB 

Step 3

Now, click on the "Next" button.

Introduction to MongoDB 

In this window, we need to provide the path for data and log directory which is required by MongoDB. Also, we can select which type of service instance we want to run for MongoDB, such as, if we say Network Service Instance or Local Service Instance.

What is MongoDB Compass?

MongoDB Compass is a graphical interface tool which displays information about a MongoDB database and also can perform the query. It is basically a simple to use, sophisticated graphical tool that allows any user to visualize and explore the MongoDB data without knowing MongoDB related queries or commands. It can be downloaded from the MongoDB official site. We can install the community edition of the MongoDB Compass since it is free for any user from the below links.

Introduction to MongoDB

How to Register for MongoDB Atlas

MongoDB not only provide the GUI tool like Compass. It also provides the MongoDB Database as service. It is known as MongoDB Atlas. MongoDB Atlas delivers the MongoDB database for the modern applications as a fully automated cloud service with all the operational and security best practices. So, using this as a service, we can easily deploy, operate and scale our database in any database platforms. So, we can register for the MongoDB Atlas on the below links.

 Introduction to MongoDB

After registration is complete, we can log into the MongoDB Atlas service from the below locations and can create new MongoDB projects for the work in the sandbox.

We will discuss about MongoDB Atlas Service in later articles in this article series.

In this article, we discussed about basic concepts of MongoDB. Also, we discussed how to install and configure MongoDB. I hope this article will help you. Any feedback or queries related to this article are most welcome. In the next article, we will discuss about how to insert records into MongoDB Database.
Debasis Saha
4 69.3k 32.6m
Next » Insert, Update And Delete Document In MongoDB - Part Two