6.B) Explain MongoDB database – 10 Marks
Answer:-
MongoDB Database Overview
MongoDB is an open-source, NoSQL database management system (DBMS) that uses a document-based approach. It is designed to provide flexibility, scalability, and high performance, making it a popular choice for modern applications like content management systems, mobile applications, e-commerce, and analytics.
Key Characteristics of MongoDB
- Non-Relational and NoSQL:
- Does not follow the traditional relational database model.
- Stores data in document-based structures.
- Cross-Platform:
- Available on multiple operating systems.
- Scalable and Flexible:
- Supports horizontal scaling and dynamic schemas for evolving data structures.
- Dynamic Schemas:
- Allows storing documents with varying fields and data types in the same collection.
- Fault Tolerant:
- Ensures data availability through distributed database features.
Core Components
- Database:
- A physical container for collections. Each database has its own set of files on the file system.
- Collection:
- Analogous to tables in relational databases.
- Can store documents with varying structures (schema-less).
- Document:
- Basic unit of data in MongoDB.
- Uses JSON-like format (BSON for storage) with key-value pairs.
Key Features of MongoDB
- Querying and Indexing:
- Supports dynamic queries and real-time data aggregation.
- Indexing on any field improves query performance.
- Fast Updates:
- In-place updates allow efficient data modification without allocating new memory.
- Atomic Operations:
- Provides atomicity for single-document operations even without multi-document transactions.
- No Complex Joins:
- Simplifies operations by avoiding the need for complex joins.
- Horizontal Scalability:
- Distributed database structure enhances availability and scalability.
- Efficient Memory Usage:
- Utilizes memory-mapped files and automatically caches frequently accessed data in RAM.
MongoDB vs. Traditional Relational Databases
- Schema: MongoDB allows schema flexibility, whereas relational databases require predefined schemas.
- Joins: MongoDB avoids joins by embedding related data within documents.
- Scalability: MongoDB supports horizontal scaling (sharding), while traditional databases often scale vertically.
Typical Use Cases
- Content management systems.
- E-commerce platforms.
- Mobile applications.
- Gaming applications.
- Analytics and logging.
Advantages
- High performance for frequent updates.
- Flexibility to store varying data structures.
- Rich query capabilities similar to SQL.
- Default indexing on
_id
for fast data access.