MongoDB
What is MongoDB?
MongoDB is a NoSQL database that stores data in flexible, JSON-like documents.
MongoDB was launched in 2009 by 10gen (now MongoDB Inc.)
MongoDB is an open-source, document-oriented NoSQL database designed to handle large amounts of data and provide fast performance.
CRUD operations in MongoDB:
Insert it into MongoDB using insertOne():
db.users.insertOne({ "name": "John Smith", "email": "john.smith@example.com", "age": 32 });
Reading Documents: Retrieve documents with find(). To get all users:
db.users.find();
To filter by age greater than 30:
db.users.find({ "age": { $gt: 30 } });
Updating Documents: Modify a document with updateOne().
db.users.updateOne( { "name": "John Smith" }, { $set: { "email": "new.email@example.com" } } );
Deleting Documents: Remove a document using deleteOne().
db.users.deleteOne({ "name": "John Smith" });
What Is MongoDB Used For?
Document-Oriented:
- Stores data in JSON format, allowing flexible and fast retrieval.
Flexible Querying:
- MongoDB supports dynamic queries by fields within documents, including regular expressions and range queries. This makes it easy to find specific data as needed.
High Speed:
- Known for its fast performance, even with massive datasets.
Flexible Indexing:
- Any field within a document can be indexed to enhance search performance, providing additional flexibility in data access.
Language Agnostic:
- It offers drivers for various programming languages like Node.js, Python, Java, and more. This versatility allows MongoDB to integrate seamlessly with different application environments.
Sharding:
- MongoDB can horizontally scale by distributing data across multiple servers using a technique called sharding. This ensures high availability and performance by spreading data load efficiently.
Benefits of MongoDB:
Handles diverse types of data (structured, semi-structured, unstructured)
Supports high availability, scalability, and real-time analytics
Use Cases:
Real-time analytics and processing of large datasets
Content management systems requiring flexible data storage (text, images, video)
Companies using MongoDB
eBay, Shutterfly, Confidential Records Inc, Toyota, Paylocity, Verizon, TIM, Marsello, MetLife, Cisco, Zendesk Inc, Brookings Institution, Forbes, Sanoma, Conrad, Helvetia, Intuit, FEMA,etc.
Disadvantages of MongoDB
ACID Support: No full ACID support (atomicity, consistency, isolation, durability)
Standardization: Lack of standardized practices compared to relational databases.
Scale-out Performance: MongoDB has scale-out (horizontal scaling) abilities via its replica sets, but the scale-out performance may be limited compared to what relational databases platforms can produce.
How MongoDB is different from RDBMS?
MongoDB
It is a non-relational and document-oriented database.
It is suitable for hierarchical data storage.
It has a dynamic schema.
It centers around the CAP theorem (Consistency, Availability, and Partition tolerance).
In terms of performance, it is much faster than RDBMS.
RDBMS
It is a relational database.
It is not suitable for hierarchical data storage.
It has a predefined schema.
It centers around ACID properties (Atomicity, Consistency, Isolation, and Durability).
In terms of performance, it is slower than MongoDB.
MongoDB is a NoSQL database that stores data in flexible, JSON-like documents.
MongoDB was launched in 2009 by 10gen (now MongoDB Inc.)
MongoDB is an open-source, document-oriented NoSQL database designed to handle large amounts of data and provide fast performance.
CRUD operations in MongoDB:
Insert it into MongoDB using insertOne():
db.users.insertOne({ "name": "John Smith", "email": "john.smith@example.com", "age": 32 });
Reading Documents: Retrieve documents with find(). To get all users:
db.users.find();
To filter by age greater than 30:
db.users.find({ "age": { $gt: 30 } });
Updating Documents: Modify a document with updateOne().
db.users.updateOne( { "name": "John Smith" }, { $set: { "email": "new.email@example.com" } } );
Deleting Documents: Remove a document using deleteOne().
db.users.deleteOne({ "name": "John Smith" });
What Is MongoDB Used For?
Document-Oriented:
- Stores data in JSON format, allowing flexible and fast retrieval.
Flexible Querying:
- MongoDB supports dynamic queries by fields within documents, including regular expressions and range queries. This makes it easy to find specific data as needed.
High Speed:
- Known for its fast performance, even with massive datasets.
Flexible Indexing:
- Any field within a document can be indexed to enhance search performance, providing additional flexibility in data access.
Language Agnostic:
- It offers drivers for various programming languages like Node.js, Python, Java, and more. This versatility allows MongoDB to integrate seamlessly with different application environments.
Sharding:
- MongoDB can horizontally scale by distributing data across multiple servers using a technique called sharding. This ensures high availability and performance by spreading data load efficiently.
Benefits of MongoDB:
Handles diverse types of data (structured, semi-structured, unstructured)
Supports high availability, scalability, and real-time analytics
Use Cases:
Real-time analytics and processing of large datasets
Content management systems requiring flexible data storage (text, images, video)
Companies using MongoDB
eBay, Shutterfly, Confidential Records Inc, Toyota, Paylocity, Verizon, TIM, Marsello, MetLife, Cisco, Zendesk Inc, Brookings Institution, Forbes, Sanoma, Conrad, Helvetia, Intuit, FEMA,etc.
Disadvantages of MongoDB
ACID Support: No full ACID support (atomicity, consistency, isolation, durability)
Standardization: Lack of standardized practices compared to relational databases.
Scale-out Performance: MongoDB has scale-out (horizontal scaling) abilities via its replica sets, but the scale-out performance may be limited compared to what relational databases platforms can produce.
How MongoDB is different from RDBMS?
MongoDB
It is a non-relational and document-oriented database.
It is suitable for hierarchical data storage.
It has a dynamic schema.
It centers around the CAP theorem (Consistency, Availability, and Partition tolerance).
In terms of performance, it is much faster than RDBMS.
RDBMS
It is a relational database.
It is not suitable for hierarchical data storage.
It has a predefined schema.
It centers around ACID properties (Atomicity, Consistency, Isolation, and Durability).
In terms of performance, it is slower than MongoDB.
Comments
Post a Comment