What is a Document Database?
A document database is a special kind of database that 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 a 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.
The main advantages of document-based databases are,
- It can store large volumes of structured, semi-structured, or unstructured data
- Each document in a collection is independent with respect to the other documents in the same collections
- The logic of the application is easy to write since there is no need for a conversation of objects between databases and applications like the SQL database.
- 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 that make MongoDB one of the most popular and enriched databases in the world of NoSQL databases. Some of the features are as below,
- MongoDB supports JSON data models with dynamic schemas.
- 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
- MongoDB supports secondary indexes which allow us to search a variety of data in a very small time span. It also provides us with different types of indexes like unique index, compound index, geospatial index, etc.
- MongoDB supports aggregation pipeline which helps us to build complex aggregations to optimize the database
- MongoDB supports Master-Slave replication
- MongoDB supports automatic load balancing features.
- MongoDB supports auto-sharding for horizontal scaling.
- MongoDB can store any type of file which can be any size without affecting our stack
- MongoDB basically uses JavaScript objects in place of the procedure.
- MongoDB supports special collection types 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 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 the 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 –
https://www.mongodb.com/download-center#community
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
Now, click on the Next button and complete the Installation Features and then click "Next".
Step 2
Step 3
Now, click on the "Next" button.
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 that 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.
https://www.mongodb.com/download-center#compass
How to Register for MongoDB Atlas
MongoDB not only provides the GUI tool like Compass. It also provides the MongoDB Database as a service. It is known as MongoDB Atlas. MongoDB Atlas delivers the MongoDB database for 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 platform. So, we can register for the MongoDB Atlas on the below links.
https://www.mongodb.com/download-center#atlas
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.
https://www.mongodb.com/cloud/atlas
We will discuss MongoDB Atlas Service in later articles in this article series.
Conclusion
In this article, we discussed 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 how to insert records into the MongoDB Database.