0% found this document useful (0 votes)
7 views42 pages

Understanding MongoDB for Big Data

Module 3 discusses MongoDB, a NoSQL database created in 2007 designed for handling large volumes of unstructured data using a document-oriented model. It highlights MongoDB's features such as cross-platform compatibility, scalability, high performance, and rich query language, along with its ability to automatically shard data and support indexing for faster queries. The module also covers basic operations like creating and managing databases and collections, as well as indexing in MongoDB.
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)
7 views42 pages

Understanding MongoDB for Big Data

Module 3 discusses MongoDB, a NoSQL database created in 2007 designed for handling large volumes of unstructured data using a document-oriented model. It highlights MongoDB's features such as cross-platform compatibility, scalability, high performance, and rich query language, along with its ability to automatically shard data and support indexing for faster queries. The module also covers basic operations like creating and managing databases and collections, as well as indexing in MongoDB.
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

BIG DATA ANALYTICS

MODULE - 3

Dr. Prasanna Lakshmi G S,


Dept. of I S E,
SVIT.
Module - 3

2
• MongoDB was invented by Dwight Merriman, Eliot Horowitz, and Kevin
Ryan in 2007.
• They co-founded a company called 10gen (later renamed MongoDB Inc.)
to develop the database. The idea came when they were working on a
cloud computing platform and realized that existing databases at the time
were not well-suited for scalability and handling large amounts of
unstructured data.
• The name MongoDB comes from the word “humongous”, reflecting
its purpose of handling very large amounts of data in a scalable way.
• Mongo → from “humongous” (meaning huge, enormous).
• DB → stands for “Database.”
• So, MongoDB = Humongous Database, designed for big,
unstructured, and rapidly growing data.
3
• MongoDB is a NoSQL database designed for storing, retrieving, and managing large volumes
of unstructured or semi-structured data. Unlike traditional relational databases (like MySQL
or Oracle) that use tables and rows, MongoDB uses a document-oriented model, where data
is stored in JSON-like documents (called BSON – Binary JSON).
• Ex:
id name age city
1 Alice 25 Bangalore

{
"_id": 1,
"name": "Alice",
"age": 25,
"city": "Bangalore"
}

4
What is MongoDB?
• MongoDB is
1. Cross-platform: It works on different operating systems like Windows, Linux, and
macOS. You can develop on one OS and run on another without issues.
2. Open source: Anyone can download MongoDB and start using it without paying.
3. Non relational: Unlike traditional databases (like MySQL), MongoDB doesn’t use
tables and rows. Instead, it stores data in documents, which are more flexible.
4. Distributed: MongoDB can run on multiple servers to handle large amounts of
data. This improves speed, availability, and reliability.
5. NoSQL: "NoSQL" means Not Only SQL. It doesn’t follow the strict structure of
SQL databases. You can store unstructured, semi-structured, or structured data
easily.
6. Document oriented data source: Data is stored in documents (like JSON format).
Each document can have different fields and structure, giving flexibility to store
5
real-world data.
Why MongoDB?
Auto Sharding
• MongoDB automatically breaks large data into
smaller pieces (shards) and stores them across
multiple servers.
• Helps in handling large-scale data and improves
performance.

Document Oriented
• Stores data in documents (like JSON), making it
easy to read and flexible to handle different
types of data.

High Performance
MongoDB is optimized for speed and efficiency,
High Availability even with large amounts of data.
With features like replication and automatic failover, MongoDB ensures that data is always
accessible. Fast In-Place Updates
You can quickly update only the required part of a
Easy Scalability: You can easily grow the database as your data grows. Add more servers
document without replacing the whole thing.
without major changes to your application.

Rich Query Language: MongoDB allows powerful and flexible queries, similar to SQL but Replication
suited for documents. • MongoDB creates copies of data (replicas) on
multiple servers.
Full Index Support • This keeps the data safe and available even if one
Just like traditional databases, MongoDB supports indexing to make data search faster. server fails. 6
7
8
Terms used in RDBMS and MongoDB

9
10
Create a database

11
Drop database

12
Data types in MongoDB

13
• Int : { “age”, 25}
• String { “name”: “Arun”}

14
15
16
17
Mongo DB query language

18
Indexes in MongoDB
What is an Index in MongoDB?
• An index in MongoDB is a special data structure
that stores a small portion of the data set in an
easy-to-traverse form.
• It helps improve the speed of query operations
by allowing MongoDB to find and retrieve specific
documents faster, similar to the index in a book.
19
20
21
Creating an Index in MongoDB
Suppose you have a collection named students with documents like
this:
{
"_id": 1,
"name": "Rahul",
"age": 21,
"department": "Computer Science"
}
• Create a Single Field Index
To create an index on the name field:
[Link]({ name: 1 })
[Link]({ name: "Rahul" })
22
• Create a Compound Index (Multiple Fields)
To create an index on both department and age:
[Link]({ department: 1, age: -1 })
[Link]({ department: "Computer
Science" }).sort({ age: -1 })
• Create a Unique Index
• To ensure that each student's name is unique:
[Link]({ name: 1 }, { unique: true })
If a duplicate value for name is inserted, MongoDB will reject it.
• List All Indexes in a Collection
[Link]()
• Drop an Index
• [Link]({ name: 1 })
23
24
Instructs mongoDB to use the index on the “category” field in
ascending order (1 means ascending order)

25
26
27
28
29
MongoDB Import

30
31
32
33
34
35
36
37
38
save() method

39
40
Creating a Collection Objective:
Create a collection named "Person".
Step 1 – View existing collections:
show collections
Example
output: Students food
[Link] [Link]

41
• Create Collection and Insert Document
• Objective: Create a collection named Students
and insert a document.

42

You might also like