Introduction to MongoDB
--
It is a Document Database.
A data or a record in MongoDB is a document, which is a data structure composed of (key:value pairs). MongoDB documents are like JSON objects for viewers but BSON in actual in the backend. The values of fields may include plain, object, arrays, and arrays of documents.
But have you ever thought the advantages of using documents? Here you go:
- Documents correspond to native data types in many programming languages.
- Embedded documents and arrays reduce need for expensive joins. Yeah its JOIN free and reduce the query complexity.
- Dynamic schema supports fluent polymorphism.
Collections/Views/On-Demand Materialized Views
MongoDB stores the documents in collections. Wait wait i know you get confuse about collection, right?
Collections are analogous to tables in relational databases. Yeah you heard it right, no confusion now.
In addition to collections, MongoDB supports:
- Read-only Views (Starting in MongoDB 3.4)
- On-Demand Materialized Views (Starting in MongoDB 4.2).
Some Key Features
High Performance
MongoDB provides high performance data persistence. In particular,
- It support for embedded data models reduces I/O activity on database system.
- Indexes support faster queries and can include keys from embedded documents and arrays. For read operations Index is like Oxygen.
Query API
The MongoDB Query API supports read and write operations (CRUD) as well as:
- Aggregation Pipeline
- Text Based Search and Geospatial Queries.
High Availability
The MongoDB’s replication facility, called replica set, which provides:
- automatic failover
- data redundancy.
A replica set is a group of MongoDB servers that maintain the same data set, providing redundancy and increasing data availability. It is highly recommended to have atleast 3 node replica set, so that incase of failover, election takes place without any issue.
Horizontal Scalability
Thew MongoDB provides horizontal scalability as part of its core functionality,
- Sharding distributes data across a cluster of machines.
- Starting in 3.4, MongoDB supports creating a zones of data based on the shard key. In a balanced cluster, MongoDB directs reads & writes covered by a zone to those shards inside the zone.
Support for Multiple Storage Engines
The MongoDB supports multiple storage engines:
- WiredTiger Storage Engine (which include support for Encryption at Rest)
- In-Memory Storage Engine
MongoDB also provides pluggable storage engine API that allows third parties to develop storage engines for MongoDB.