SlideShare a Scribd company logo
Indira Gandhi Delhi Technical University for Women
Speakers:
● Ankur Raina ( ankur.raina@mongodb.com )
● Pooja Gupta ( pooja.gupta@mongodb.com )
900+
employees
About
MongoDB,
Inc.
4,300+
customers
19 offices
worldwide
MongoDB Use Cases
Single View Internet of Things Mobile Real-Time Analytics
Catalog Personalization Content Management
AGENDA
• Introduction to MongoDB
– MongoDB Database
– Document Model
– BSON
– Data Model
– CRUD operations
• Break (10 mins)
• High Availability and Scalability
– Replication
– Sharding
• Break (15 mins)
• Hands-On MongoDB
MongoDB Database
MongoDB
• Open-source, general purpose document database
• Document: Field and Value pairs
• Similar to JSON objects
Advantages
• Documents (i.e objects) correspond to native datatypes in many
programming languages
• Reduce expensive joins by embedding
• Dynamic schema - change on the fly
Document
Unique Identification - Notice the fields
Document (contd.)
Spot the difference! - Did you notice the flexibility?
JSON? BSON?
• BSON is a binary-encoded serialization of JSON-like documents ( bsonspec.org )
• More data types such as BinData and Date
• Lightweight, Traversable, Efficient
Data Model
• Flexible Schema
• Collections do not enforce Document structure
• Consider the application usage patterns of data
• Normalisation rules do not apply directly!
• References and Embedding
• 16 MB size limit of documents
• Operation are atomic at document level
Let’s insert() a document in the collection
Let’s find() some documents from our collection
New Requirement
• update() PAN numbers of citizens
• Single PAN number of “some” citizens - Not everyone has a PAN card!
• None of our documents has a “pan_card” field
• update() phone numbers of all citizens. Multiple phone numbers.
• Note that we are using an array to store these
New Requirement
• update() complete “permanent address” of citizens
• A field named permanent_address containing sub-fields:
– house_no
– street
– landmark
– locality
– district
– state
– pincode
– map i.e. long-lat
Sub-documents & Geo-JSON
Relational
TABLE 1 : CITIZEN_INFO
id
first_name
last_name
registered_on
pan_card
TABLE 2 :
PHONE_NUMBERS
person_id
phone_number
TABLE 3 :
PERMANENT_ADDRESS
person_id
house_no
street
landmark
locality
pincode
longitude
latitude
TABLE 4:
PINCODE_LOOKUP
pincode
locality
district
state
Doesn’t it look like a natural fit
for this data?
Let’s do some referencing
• The government would like to keep track of criminal records associated with citizens
Executables
SQL -> MongoDB
Structured Query Language (SQL) MongoDB Query Language (MQL)
CREATE TABLE insert() / createCollection()
ALTER TABLE - ADD COLUMN update() - $set
ALTER TABLE - DROP COLUMN update() - $unset
CREATE INDEX createIndex()
DROP TABLE drop()
INSERT INTO - VALUES insert()
SELECT find()
UPDATE - SET update() - $set
DELETE remove()
CreateReadUpdateDelete
Introduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUW
Citizen Database
Banking Application
Sim Card Subscribers
Gas Connection Subscription
Biometric Details
Example
Replica Set
Replica Set- Failure
Replica Set- Failover
Replica Set- Recovery
Replica Set- Recovered
Strong Consistency
Strong Consistency
Introduction to MongoDB at IGDTUW
Pros:
● Most of the software can easily take
advantage of vertical scaling
● Easy to manage and install hardware
within a single machine
Pros:
● Increases performance in small steps as needed
● Can scale out the system as much as you need
Cons:
● Requires substantial financial investment
● Not possible to scale up vertically after a
certain limit
Cons:
● Need to set up the additional servers to handle
the data distribution and parallel processing
capabilities
Introduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUW
Hands-On
MongoDB
Download MongoDB Community Server: https://www.mongodb.com/download-center#community
mongo shell
• Download from MongoDB Atlas (MongoDB database-as-a-service)
• Connect to mongo shell - an interactive JavaScript interface to MongoDB
• https://docs.atlas.mongodb.com/getting-started/
Let’s first restore data from an existing dump
Don’t worry, if you don’t get this. Just follow the steps !
• Go to https://github.com/Ankur10gen/SampleDataMongoDB
• Download the zip file and extract it
• cd SampleDataMongoDB-master/mongodump-citizendata_09_10/
mongorestore --db <DBNAME> --host <”ReplicaSetName/Hosts1,Host2,Host3”> --
authenticationDatabase admin --ssl --username admin --password <PASSWORD
e.g.: mongorestore --db demo1 demo1/ --host "Cluster0-shard-0/cluster0-shard-
00-00-ydjii.mongodb.net:27017,cluster0-shard-00-01-
ydjii.mongodb.net:27017,cluster0-shard-00-02-ydjii.mongodb.net:27017" --
authenticationDatabase admin --ssl --username admin --password <PASSWORD>
Great! You have made it! You are ready to use the mongo shell now!
Let’s see which databases exist, connect to a database & see the
collections inside it.
Note: There can be many databases in one mongod deployment and each database can have
several collections.
• show dbs
• use demo1
• show collections
Ex1: Find one citizen with last_name ‘SHARMA’
> db.citizendata.findOne({last_name:"SHARMA"})
SELECT * FROM citizendata WHERE last_name = “SHARMA” LIMIT 1;
Ex2: Find citizens with first_name ‘AJAY’
> db.citizendata.find({"first_name":"AJAY"})
SELECT * FROM citizendata WHERE first_name = “AJAY”
Ex3: Limit the previous result set to 5 documents
> db.citizendata.find({"first_name":"AJAY"}).limit(5)
SELECT * FROM citizendata WHERE first_name = “AJAY” LIMIT 5
Ex4: When was person with "_id" : "678943212601" registered?
> db.citizendata.find( { "_id": "678943212601" } , { "registered_on":1 } )
SELECT registered_on FROM citizendata WHERE _id = "678943212601";
Ex5: Find the count of people with state ‘HARYANA’. Note that state is a
field inside permanent_address.
> db.citizendata.find( { "permanent_address.state": "HARYANA" } ).count()
YOU MAY NEED TO DO A JOIN AND WE DON’T WANT TO GO THERE.
======================================= enjoying?
Ex6: CREATE AN INDEX ON phone_numbers
> db.citizendata.createIndex( { phone_numbers: 1 } )
CREATE INDEX phone_numbers_1 ON citizendata (phone_numbers)
Ex7: Find details of a person with phone_number 8855915314. Note that
phone_numbers is an array type field.
> db.citizendata.find( { "phone_numbers": "8855915314" } ).pretty()
Ex8: Find _id of citizens with first_name REVA or ABEER
> db.citizendata.find( { "first_name": { "$in" : [ "REVA", "ABEER" ] } }, { _id: 1 } )
Ex9: Find the count of people with first_name SANDEEP in each state. We are
using the MongoDB Aggregation Pipeline.
> db.citizendata.aggregate(
[
{ $match : { "first_name":'SANDEEP' } },
{ $group : { _id : "$permanent_address.state", count: {$sum: 1} } }
]
)
In SQL, you’ll use a GROUP BY clause for it. And may be some joins to bring in
this state info from another table.
Ex10: Let’s sort our citizens in descending order with last_name ‘VERMA’ on
the basis of pan_card information using aggregation pipeline and limit our
result set to 10. Project only the phone numbers with NO _id field.
> db.citizendata.aggregate(
[
{ $match : { "last_name":'VERMA' } },
{ $sort : { "pan_card" : -1 } },
{ $project : { "_id": 0, "pan_card":1,"phone_numbers":1 } },
{ $limit : 10 }
]
)
I hope you enjoyed this session!
Share your experience on the social networks! @MongoDB
Ad

More Related Content

What's hot (19)

Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
MongoDB
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDB
MongoDB
 
Intro to mongodb mongouk jun2010
Intro to mongodb mongouk jun2010Intro to mongodb mongouk jun2010
Intro to mongodb mongouk jun2010
Skills Matter
 
Mongo DB 102
Mongo DB 102Mongo DB 102
Mongo DB 102
Abhijeet Vaikar
 
The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation Framework
MongoDB
 
MongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
MongoDB Europe 2016 - Advanced MongoDB Aggregation PipelinesMongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
MongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
MongoDB
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD OperationsMongo Nosql CRUD Operations
Mongo Nosql CRUD Operations
anujaggarwal49
 
Webinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDBWebinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDB
MongoDB
 
MongoDB - javascript for your data
MongoDB - javascript for your dataMongoDB - javascript for your data
MongoDB - javascript for your data
aaronheckmann
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
Eliot Horowitz
 
Webinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation FrameworkWebinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation Framework
MongoDB
 
Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2
MongoDB
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDB
MongoDB
 
Doing More with MongoDB Aggregation
Doing More with MongoDB AggregationDoing More with MongoDB Aggregation
Doing More with MongoDB Aggregation
MongoDB
 
Mongo db – document oriented database
Mongo db – document oriented databaseMongo db – document oriented database
Mongo db – document oriented database
Wojciech Sznapka
 
Omnibus database machine
Omnibus database machineOmnibus database machine
Omnibus database machine
Aleck Landgraf
 
Working with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDBWorking with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDB
ScaleGrid.io
 
Getting Started with Geospatial Data in MongoDB
Getting Started with Geospatial Data in MongoDBGetting Started with Geospatial Data in MongoDB
Getting Started with Geospatial Data in MongoDB
MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Algiers Tech Meetup
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
MongoDB
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDB
MongoDB
 
Intro to mongodb mongouk jun2010
Intro to mongodb mongouk jun2010Intro to mongodb mongouk jun2010
Intro to mongodb mongouk jun2010
Skills Matter
 
The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation Framework
MongoDB
 
MongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
MongoDB Europe 2016 - Advanced MongoDB Aggregation PipelinesMongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
MongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
MongoDB
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD OperationsMongo Nosql CRUD Operations
Mongo Nosql CRUD Operations
anujaggarwal49
 
Webinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDBWebinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDB
MongoDB
 
MongoDB - javascript for your data
MongoDB - javascript for your dataMongoDB - javascript for your data
MongoDB - javascript for your data
aaronheckmann
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
Eliot Horowitz
 
Webinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation FrameworkWebinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation Framework
MongoDB
 
Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2
MongoDB
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDB
MongoDB
 
Doing More with MongoDB Aggregation
Doing More with MongoDB AggregationDoing More with MongoDB Aggregation
Doing More with MongoDB Aggregation
MongoDB
 
Mongo db – document oriented database
Mongo db – document oriented databaseMongo db – document oriented database
Mongo db – document oriented database
Wojciech Sznapka
 
Omnibus database machine
Omnibus database machineOmnibus database machine
Omnibus database machine
Aleck Landgraf
 
Working with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDBWorking with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDB
ScaleGrid.io
 
Getting Started with Geospatial Data in MongoDB
Getting Started with Geospatial Data in MongoDBGetting Started with Geospatial Data in MongoDB
Getting Started with Geospatial Data in MongoDB
MongoDB
 

Similar to Introduction to MongoDB at IGDTUW (20)

Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET Driver
MongoDB
 
RedisConf18 - Redis Memory Optimization
RedisConf18 - Redis Memory OptimizationRedisConf18 - Redis Memory Optimization
RedisConf18 - Redis Memory Optimization
Redis Labs
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentation
Murat Çakal
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
Norberto Leite
 
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: TutorialMongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB
 
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDBMongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB
 
Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011
rogerbodamer
 
MongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and ImplicationsMongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and Implications
MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
MongoDB
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
Analytics with MongoDB Aggregation Framework and Hadoop Connector
Analytics with MongoDB Aggregation Framework and Hadoop ConnectorAnalytics with MongoDB Aggregation Framework and Hadoop Connector
Analytics with MongoDB Aggregation Framework and Hadoop Connector
Henrik Ingo
 
Eagle6 mongo dc revised
Eagle6 mongo dc revisedEagle6 mongo dc revised
Eagle6 mongo dc revised
MongoDB
 
Eagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessEagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational Awareness
MongoDB
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
NETWAYS
 
Simplifying & accelerating application development with MongoDB's intelligent...
Simplifying & accelerating application development with MongoDB's intelligent...Simplifying & accelerating application development with MongoDB's intelligent...
Simplifying & accelerating application development with MongoDB's intelligent...
Maxime Beugnet
 
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
MongoDB
 
Superficial mongo db
Superficial mongo dbSuperficial mongo db
Superficial mongo db
DaeMyung Kang
 
Mongo db
Mongo dbMongo db
Mongo db
Gyanendra Yadav
 
Practical JSON in MySQL 5.7 and Beyond
Practical JSON in MySQL 5.7 and BeyondPractical JSON in MySQL 5.7 and Beyond
Practical JSON in MySQL 5.7 and Beyond
Ike Walker
 
Data Analytics with MongoDB - Jane Fine
Data Analytics with MongoDB - Jane FineData Analytics with MongoDB - Jane Fine
Data Analytics with MongoDB - Jane Fine
MongoDB
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET Driver
MongoDB
 
RedisConf18 - Redis Memory Optimization
RedisConf18 - Redis Memory OptimizationRedisConf18 - Redis Memory Optimization
RedisConf18 - Redis Memory Optimization
Redis Labs
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentation
Murat Çakal
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
Norberto Leite
 
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: TutorialMongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB
 
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDBMongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB
 
Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011
rogerbodamer
 
MongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and ImplicationsMongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and Implications
MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
MongoDB
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
Analytics with MongoDB Aggregation Framework and Hadoop Connector
Analytics with MongoDB Aggregation Framework and Hadoop ConnectorAnalytics with MongoDB Aggregation Framework and Hadoop Connector
Analytics with MongoDB Aggregation Framework and Hadoop Connector
Henrik Ingo
 
Eagle6 mongo dc revised
Eagle6 mongo dc revisedEagle6 mongo dc revised
Eagle6 mongo dc revised
MongoDB
 
Eagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessEagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational Awareness
MongoDB
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
NETWAYS
 
Simplifying & accelerating application development with MongoDB's intelligent...
Simplifying & accelerating application development with MongoDB's intelligent...Simplifying & accelerating application development with MongoDB's intelligent...
Simplifying & accelerating application development with MongoDB's intelligent...
Maxime Beugnet
 
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
MongoDB
 
Superficial mongo db
Superficial mongo dbSuperficial mongo db
Superficial mongo db
DaeMyung Kang
 
Practical JSON in MySQL 5.7 and Beyond
Practical JSON in MySQL 5.7 and BeyondPractical JSON in MySQL 5.7 and Beyond
Practical JSON in MySQL 5.7 and Beyond
Ike Walker
 
Data Analytics with MongoDB - Jane Fine
Data Analytics with MongoDB - Jane FineData Analytics with MongoDB - Jane Fine
Data Analytics with MongoDB - Jane Fine
MongoDB
 
Ad

More from Ankur Raina (8)

PyMongo for PyCon First Draft
PyMongo for PyCon First DraftPyMongo for PyCon First Draft
PyMongo for PyCon First Draft
Ankur Raina
 
Mug17 gurgaon
Mug17 gurgaonMug17 gurgaon
Mug17 gurgaon
Ankur Raina
 
Ankur py mongo.pptx
Ankur py mongo.pptxAnkur py mongo.pptx
Ankur py mongo.pptx
Ankur Raina
 
E
EE
E
Ankur Raina
 
Oracle SQL Basics by Ankur Raina
Oracle SQL Basics by Ankur RainaOracle SQL Basics by Ankur Raina
Oracle SQL Basics by Ankur Raina
Ankur Raina
 
Cloud computing
Cloud computingCloud computing
Cloud computing
Ankur Raina
 
Sql project presentation
Sql project presentationSql project presentation
Sql project presentation
Ankur Raina
 
Big data
Big dataBig data
Big data
Ankur Raina
 
PyMongo for PyCon First Draft
PyMongo for PyCon First DraftPyMongo for PyCon First Draft
PyMongo for PyCon First Draft
Ankur Raina
 
Ankur py mongo.pptx
Ankur py mongo.pptxAnkur py mongo.pptx
Ankur py mongo.pptx
Ankur Raina
 
Oracle SQL Basics by Ankur Raina
Oracle SQL Basics by Ankur RainaOracle SQL Basics by Ankur Raina
Oracle SQL Basics by Ankur Raina
Ankur Raina
 
Sql project presentation
Sql project presentationSql project presentation
Sql project presentation
Ankur Raina
 
Ad

Recently uploaded (20)

tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 

Introduction to MongoDB at IGDTUW

  • 1. Indira Gandhi Delhi Technical University for Women Speakers: ● Ankur Raina ( [email protected] ) ● Pooja Gupta ( [email protected] )
  • 3. MongoDB Use Cases Single View Internet of Things Mobile Real-Time Analytics Catalog Personalization Content Management
  • 4. AGENDA • Introduction to MongoDB – MongoDB Database – Document Model – BSON – Data Model – CRUD operations • Break (10 mins) • High Availability and Scalability – Replication – Sharding • Break (15 mins) • Hands-On MongoDB
  • 6. MongoDB • Open-source, general purpose document database • Document: Field and Value pairs • Similar to JSON objects
  • 7. Advantages • Documents (i.e objects) correspond to native datatypes in many programming languages • Reduce expensive joins by embedding • Dynamic schema - change on the fly
  • 9. Document (contd.) Spot the difference! - Did you notice the flexibility?
  • 10. JSON? BSON? • BSON is a binary-encoded serialization of JSON-like documents ( bsonspec.org ) • More data types such as BinData and Date • Lightweight, Traversable, Efficient
  • 11. Data Model • Flexible Schema • Collections do not enforce Document structure • Consider the application usage patterns of data • Normalisation rules do not apply directly! • References and Embedding • 16 MB size limit of documents • Operation are atomic at document level
  • 12. Let’s insert() a document in the collection
  • 13. Let’s find() some documents from our collection
  • 14. New Requirement • update() PAN numbers of citizens • Single PAN number of “some” citizens - Not everyone has a PAN card! • None of our documents has a “pan_card” field
  • 15. • update() phone numbers of all citizens. Multiple phone numbers. • Note that we are using an array to store these
  • 16. New Requirement • update() complete “permanent address” of citizens • A field named permanent_address containing sub-fields: – house_no – street – landmark – locality – district – state – pincode – map i.e. long-lat
  • 18. Relational TABLE 1 : CITIZEN_INFO id first_name last_name registered_on pan_card TABLE 2 : PHONE_NUMBERS person_id phone_number TABLE 3 : PERMANENT_ADDRESS person_id house_no street landmark locality pincode longitude latitude TABLE 4: PINCODE_LOOKUP pincode locality district state
  • 19. Doesn’t it look like a natural fit for this data?
  • 20. Let’s do some referencing • The government would like to keep track of criminal records associated with citizens
  • 22. SQL -> MongoDB Structured Query Language (SQL) MongoDB Query Language (MQL) CREATE TABLE insert() / createCollection() ALTER TABLE - ADD COLUMN update() - $set ALTER TABLE - DROP COLUMN update() - $unset CREATE INDEX createIndex() DROP TABLE drop() INSERT INTO - VALUES insert() SELECT find() UPDATE - SET update() - $set DELETE remove() CreateReadUpdateDelete
  • 25. Citizen Database Banking Application Sim Card Subscribers Gas Connection Subscription Biometric Details Example
  • 34. Pros: ● Most of the software can easily take advantage of vertical scaling ● Easy to manage and install hardware within a single machine Pros: ● Increases performance in small steps as needed ● Can scale out the system as much as you need Cons: ● Requires substantial financial investment ● Not possible to scale up vertically after a certain limit Cons: ● Need to set up the additional servers to handle the data distribution and parallel processing capabilities
  • 38. Hands-On MongoDB Download MongoDB Community Server: https://www.mongodb.com/download-center#community
  • 39. mongo shell • Download from MongoDB Atlas (MongoDB database-as-a-service) • Connect to mongo shell - an interactive JavaScript interface to MongoDB • https://docs.atlas.mongodb.com/getting-started/
  • 40. Let’s first restore data from an existing dump Don’t worry, if you don’t get this. Just follow the steps ! • Go to https://github.com/Ankur10gen/SampleDataMongoDB • Download the zip file and extract it • cd SampleDataMongoDB-master/mongodump-citizendata_09_10/ mongorestore --db <DBNAME> --host <”ReplicaSetName/Hosts1,Host2,Host3”> -- authenticationDatabase admin --ssl --username admin --password <PASSWORD e.g.: mongorestore --db demo1 demo1/ --host "Cluster0-shard-0/cluster0-shard- 00-00-ydjii.mongodb.net:27017,cluster0-shard-00-01- ydjii.mongodb.net:27017,cluster0-shard-00-02-ydjii.mongodb.net:27017" -- authenticationDatabase admin --ssl --username admin --password <PASSWORD>
  • 41. Great! You have made it! You are ready to use the mongo shell now! Let’s see which databases exist, connect to a database & see the collections inside it. Note: There can be many databases in one mongod deployment and each database can have several collections. • show dbs • use demo1 • show collections
  • 42. Ex1: Find one citizen with last_name ‘SHARMA’ > db.citizendata.findOne({last_name:"SHARMA"}) SELECT * FROM citizendata WHERE last_name = “SHARMA” LIMIT 1; Ex2: Find citizens with first_name ‘AJAY’ > db.citizendata.find({"first_name":"AJAY"}) SELECT * FROM citizendata WHERE first_name = “AJAY” Ex3: Limit the previous result set to 5 documents > db.citizendata.find({"first_name":"AJAY"}).limit(5) SELECT * FROM citizendata WHERE first_name = “AJAY” LIMIT 5
  • 43. Ex4: When was person with "_id" : "678943212601" registered? > db.citizendata.find( { "_id": "678943212601" } , { "registered_on":1 } ) SELECT registered_on FROM citizendata WHERE _id = "678943212601"; Ex5: Find the count of people with state ‘HARYANA’. Note that state is a field inside permanent_address. > db.citizendata.find( { "permanent_address.state": "HARYANA" } ).count() YOU MAY NEED TO DO A JOIN AND WE DON’T WANT TO GO THERE. ======================================= enjoying?
  • 44. Ex6: CREATE AN INDEX ON phone_numbers > db.citizendata.createIndex( { phone_numbers: 1 } ) CREATE INDEX phone_numbers_1 ON citizendata (phone_numbers) Ex7: Find details of a person with phone_number 8855915314. Note that phone_numbers is an array type field. > db.citizendata.find( { "phone_numbers": "8855915314" } ).pretty() Ex8: Find _id of citizens with first_name REVA or ABEER > db.citizendata.find( { "first_name": { "$in" : [ "REVA", "ABEER" ] } }, { _id: 1 } )
  • 45. Ex9: Find the count of people with first_name SANDEEP in each state. We are using the MongoDB Aggregation Pipeline. > db.citizendata.aggregate( [ { $match : { "first_name":'SANDEEP' } }, { $group : { _id : "$permanent_address.state", count: {$sum: 1} } } ] ) In SQL, you’ll use a GROUP BY clause for it. And may be some joins to bring in this state info from another table.
  • 46. Ex10: Let’s sort our citizens in descending order with last_name ‘VERMA’ on the basis of pan_card information using aggregation pipeline and limit our result set to 10. Project only the phone numbers with NO _id field. > db.citizendata.aggregate( [ { $match : { "last_name":'VERMA' } }, { $sort : { "pan_card" : -1 } }, { $project : { "_id": 0, "pan_card":1,"phone_numbers":1 } }, { $limit : 10 } ] )
  • 47. I hope you enjoyed this session! Share your experience on the social networks! @MongoDB