MONGODB
MONGODB
MongoDB
1
"Imagine a database where you
don’t have to define your table
structure in advance, and you
can store any kind of data—text,
numbers, arrays, even nested
objects—in a single record. How
would this change the way you
design or scale your applications
3
MongoDB
MongoDB is a powerful, open-source NoSQL
database that offers a document-oriented data
model, providing a flexible alternative to
traditional relational databases. Unlike SQL
databases, MongoDB stores data in BSON
format, which is similar to JSON, enabling
efficient and scalable data storage and retrieval.
What is NoSQL?
•Not only SQL
•SQL means
Relational model
Strong typing
ACID compliance
Normalization
…
•NoSQL means more freedom or
flexibility
5
Relevance to Big Data
•Data gets bigger
•Traditional RDBMS cannot scale well
•RDBMS is tied to its data and
query processing models
•NoSQL relaxes some of the
restrictions of RDBMS to provide a
better performance
6
Advantages of NoSQL
•Handles Big Data
•Data Models – No predefined schema
•Data Structure – NoSQL handles semi-
structured data
•Cheaper to manage
•Scaling – Scale out / horizonal scaling
7
Advantages of RDBMS
•Better for relational data
•Data normalization
•Well-established query language (SQL)
•Data Integrity
•ACID Compliance
8
Structured/Semi-structured
ID Name Email …
1 Jack [email protected]
2 Jill [email protected]
3 Alex [email protected]
Document 1
9
Document Data
Model
•Relational model (RDBMS)
Database
o
Relation (Table) : Schema
- Record (Tuple) : Data
•Document Model Document 1
{ “id”: 1, “name”:”Jack”, “email”: “[email protected]”,
o
Collection : No predefined schema
- Document : Schema+data
•No need to define/update schema
•No need to create collections
10
Document Format
•MongoDB natively works with JSON
documents
•For efficiency, documents are stored in a
binary format called BSON (i.e., binary
JSON)
•Like JSON, both schema and data are
stored in each document
11
How to Use MongoDB
Install: Check the MongoDB website
https://docs.mongodb.com/manual/installation/
Create collection and insert a document
db.users.insert({name: “Jack”,
email: “[email protected]”});
Retrieve all/some documents
db.users.find();
db.users.find({name:
“Jack”});
Update
db.users.update({name: "Jack"}, {$set:
{hobby: "cooking"}});
updateOne, updateMany,
replaceOne
Delete
db.users.remove({name: "Alex"});
deleteOne,
deleteMany 13
https://docs.mongodb.com/manual/crud/
Key Difference between MongoDB & SQL
MySQL
MongoDB
Data Storage Collections containing JSON documents Tables with rows and columns
Limited document querying, no support Uses SQL for querying and advanced
Query Language
for joins analytics functions
Post Lecture Assessment