MongoDB Tutorial

MongoDB is a NoSQL Database. It is an open-source document-oriented database written in C++. it is used for a high volume of data storage. It is not a relational database. It has important features like indexing, regular expression, sharding data, etc.

Key Features:

1. Document-Oriented: Data is stored in collections of documents (similar to rows in a table), which can have various fields and structures.

2 Flexible Schema: MongoDB allows documents to have different structures, meaning fields can be added or removed dynamically.

3. Scalability: MongoDB is designed for horizontal scalability, meaning you can distribute your data across multiple servers easily.

4. High Performance: It’s optimized for high write and read throughput, making it suitable for real-time applications.

5. Indexing and Aggregation: MongoDB supports indexing, allowing for fast querying, and has powerful aggregation features for data processing.

6. Replication and Sharding: It provides features like replication for high availability and sharding for distributing data across multiple machines.

Advantages:-

Schemaless

Scalability

Performance

High Availability

etc.

Note:- Datastore in the MongoDB as a key-value format.

Example:-

employees collection


{
	name:"John",
	age:35,
	department:"Department A"

}

Mongo DB works based on collection and Document

Collection:- Collection is a group of MongoDB documents. It is the equivalent of an RDBMS table but it has not enforced the same structure of the document so it is possible documents have different structures in the collection.

Document:- it is based on key-value pairs and document the same as a row in RDBMS. Documents have a dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structures.

Example:- employees collection
One Document has this structure


{
	name:"John",
	age:35,
	department:"Department A"

}

The second Document has a different structure


{
	name:"John",
	age:35,
	skill:["NodeJS","Angular","MongoDB","MySQL"],
	department:"Department A",


}

compare RDBMS and Mongo DB structure

RDBMS

MongoDB

Table

Collection

Row

Document

Column

Key

MongoDB Tutorial – Interview Questions

Q 1: What is MongoDB?
Ans: MongoDB is a NoSQL, document-oriented database that stores data in JSON-like BSON format. It is designed for scalability, high performance, and flexible schema design.
Q 2: What are the main features of MongoDB?
Ans: MongoDB provides high scalability, flexible schema, high availability, indexing support, and an aggregation framework for advanced data processing
Q 3: What is BSON in MongoDB?
Ans: BSON (Binary JSON) is a binary-encoded serialization format used by MongoDB to store documents efficiently
Q 4: How is MongoDB different from SQL databases?
Ans: MongoDB stores data in collections and documents instead of tables and rows. It supports flexible schema and horizontal scaling.
Q 5: Where is MongoDB commonly used?
Ans: MongoDB is widely used in real-time analytics, content management systems, IoT applications, and big data applications.

Related MongoDB Tutorial Topics