0% found this document useful (0 votes)
14 views12 pages

Mongo DB

MongoDB is an open-source NoSQL database that uses a flexible, JSON-like format to store unstructured or semi-structured data, allowing for dynamic data models. Key features include document-oriented storage, scalability through sharding, and high performance for real-time applications. It supports BSON for efficient data representation and offers schema flexibility, making it suitable for various applications like e-commerce and IoT.

Uploaded by

Divya Mannava
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views12 pages

Mongo DB

MongoDB is an open-source NoSQL database that uses a flexible, JSON-like format to store unstructured or semi-structured data, allowing for dynamic data models. Key features include document-oriented storage, scalability through sharding, and high performance for real-time applications. It supports BSON for efficient data representation and offers schema flexibility, making it suitable for various applications like e-commerce and IoT.

Uploaded by

Divya Mannava
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

What is MongoDB?

MongoDB is an open-source NoSQL database designed for handling large volumes of


unstructured or semi-structured data. Unlike traditional relational databases, MongoDB stores
data in a flexible, JSON-like format, making it easier to work with dynamic and complex data
models.
Key Features of
MongoDB
•Document-Oriented Storage: Data is stored in the form of JSON-like documents, providing
flexibility in structure.
•Scalability: Supports horizontal scaling through sharding, allowing distributed storage across
multiple servers.
•Schema Flexibility: No rigid schemas, enabling dynamic adjustments to data structures.
•High Performance: Optimized for quick read and write operations, suitable for real-time
applications.
•Cross-Platform Support: Runs on Windows, macOS, Linux, and is deployable on cloud or
containerized environments.
JSON and
MongoDB is a NoSQL database
MongoDB
that stores data in a format similar to JSON (JavaScript Object
Notation). However, it uses BSON (Binary JSON) under the hood, which is a binary representation of
JSON that supports additional data types and optimizations. Below, we break down the relationship
and key concepts of JSON and MongoDB: 2. BSON: MongoDB's Internal Format
1. JSON in MongoDB •Why BSON? JSON is text-based and does not
•Data Structure: MongoDB collections store documents support all data types efficiently. BSON extends
that are structured as JSON-like objects. These documents JSON by adding support for types such as:
consist of field-value pairs where values can be: •Date: BSON has a dedicated Date type,
• Primitive types (strings, numbers, Booleans) while JSON requires dates to be strings.
• Arrays •Binary Data: BSON supports binary data
• Nested documents (objects) directly.
•Ease of Use: JSON’s simplicity and human-readable •Embedded Documents: Allows for
structure make it intuitive for developers working with complex nested structures.
MongoDB. •Efficiency: BSON is optimized for storage and
performance, including size efficiency through
Aspect JSON MongoDB

A lightweight data interchange format in text, easy to read and A NoSQL database that stores data in a document-oriented, JSON-like
Definition
write. format (BSON).

Internally uses BSON (Binary JSON), optimized for storage and


Storage Format Text-based format for storing and exchanging data.
performance, with additional data types like Date and Binary.

Collections of documents, where each document is a BSON


Data Structure Key-value pairs in a hierarchical, nested structure. representation of JSON-like data, supporting arrays, objects, and
embedded structures.

Schema-less collections; documents can have varying structures within


Schema Schema-less, flexible structure.
the same collection.

Extends JSON with additional data types like Date, Binary, Objected,
Supported Data Types Strings, numbers, arrays, objects, Booleans, and null.
Decimal128, and Geospatial types.

Used as the primary data format for inserting, querying, and JSON-like queries and updates, as well as importing/exporting data, rely
Use Case in MongoDB
exchanging data with MongoDB. on the JSON format for simplicity and interoperability.

Supports JSON-like queries with advanced operators for filtering,


Queries Purely represents data, no query support.
aggregation, and updates.

MongoDB documents use JSON-like syntax: { "name": "Alice", "age":


Example Syntax { "name": "Alice", "age": 25 }
25 }.
Tools like mongoexport and mongoimport work with JSON for exporting
Export/Import Tools Cannot directly manage databases. and importing data: mongoexport --db mydb --collection mycol --out
data.json.

Enables CRUD operations (insertOne, find, update, delete) using JSON-


Operations Represents data for storage or transmission.
like documents and queries.

MongoDB supports advanced aggregation pipelines using JSON-like


Aggregation Support Not applicable.
syntax for data transformation and analysis.

Supports direct JSON integration with APIs, SDKs, and programming


Widely used for APIs, configuration files, and data exchange
Integration languages like Python, Node.js, and Java for seamless data manipulation
between systems.
and querying.
Adopting a Non-Relational
Approach
•No Tables: Instead of tables, MongoDB uses collections to store documents.
•Flexible Structure: Documents in the same collection can have different fields or structures.
•Use Cases: Ideal for applications requiring dynamic schemas, such as e-commerce platforms, IoT,
and social media apps.
Performa
nce
 Horizontal Scalability:
 MongoDB supports sharding, distributing data across multiple servers to handle large-scale
datasets.
 Ensures high availability and fault tolerance.
 Efficient Reads and Writes:
 Optimized for fast data access, particularly for applications requiring high-throughput
operations.
 Indexing:
 Supports various types of indexes (e.g., single field, compound, text, geospatial) to
accelerate query performance.
Feature

•Schema Flexibility:
Considerations
• No rigid schema enforcement, allowing developers to adapt data models as needed.
•Aggregation Framework:
• Provides a powerful tool for data processing and transformation.
•ACID Transactions:
• Supports multi-document transactions in modern versions for consistent and reliable
operations.
•Limitations:
• May lack advanced SQL features like JOINs, though embedded documents can often replace
this functionality.
• Requires careful schema design to avoid data redundancy and maintain performance.
Running the Database
Anywhere
•Local Machine:
Install MongoDB on your operating system. •Docker:

Steps: Run MongoDB in a container.


1.Download MongoDB from the Steps:
official website. 1.Pull the MongoDB image: docker pull
2.Install and run the mongod service. mongo.
•MongoDB Atlas (Cloud): 2.Start the container: docker run -d -p
Use the managed cloud service by MongoDB. 27017:27017 --name mongodb
Steps: mongo.
1.Sign up on MongoDB Atlas. •On-Premise Server:

2.Create a cluster and use the provided Deploy MongoDB on your own server for
connection string to connect. full control.
Generating or
1. In MongoDB, keys represent field names in a document, which is a record in a collection.
Creating
You don't need to manually generate keys; they areKeys
defined as part of the document structure when
you insert a document into a collection.
•_id Field:
•Every MongoDB document has a unique _id field automatically created by MongoDB.
•It acts as the primary key for the document.
•Example:
{ "_id": “1", "name": “irfan", "age": 24 }
•You can manually specify the _id field during insertion, but it must be unique within the
collection.
•Custom Keys:
•You can define custom keys to structure your data.
•Example:
{ "username": “irfan", "email": “[email protected], "created_at": "2024-12-09" }
Using Keys and
MongoDB is a document-oriented NoSQL database where data is stored in BSON (Binary JSON)
Values
format. Each document is essentially a set of key-value pairs.
•Inserting Data:
•Key-value pairs are defined when inserting data into a collection.
•Example (using MongoDB shell):
db.users.insertOne({ "name": “Avi", "email": “[email protected]", "age": 24 });
•Querying Data:
•Keys are used in queries to retrieve specific data.
•Example:
db.users.find({ "name": “irfan" });
•Updating Data:
•Keys are used to identify fields for updating values.
•Example:
db.users.updateOne( { "name": “irfan" }, { $set: { "age": 25 } } );
Implementing Collections in
MongoDB

A collection in MongoDB is like a table in relational databases. It stores a group of documents.


Creating a Collection
Collections in MongoDB are created implicitly when you insert the first document.
•Explicitly Creating a Collection:
b.createCollection("users");
•Inserting into a Collection: When you insert a document into a non-existent collection, MongoDB
creates the collection automatically.
db.products.insertOne({ "product_name": "Laptop", "price": 60000, "quantity": 25 });

You might also like