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

More Related Content

PPTX
MongoDB Aggregations Indexing and Profiling
PDF
When to Use MongoDB
PDF
Mongo Presentation by Metatagg Solutions
PPTX
Introduction to MongoDB and Hadoop
PPTX
Querying mongo db
PPT
Introduction to MongoDB
PPT
PhpstudyTokyo MongoDB PHP CakePHP
PPTX
The Aggregation Framework
MongoDB Aggregations Indexing and Profiling
When to Use MongoDB
Mongo Presentation by Metatagg Solutions
Introduction to MongoDB and Hadoop
Querying mongo db
Introduction to MongoDB
PhpstudyTokyo MongoDB PHP CakePHP
The Aggregation Framework

What's hot (19)

PPTX
Webinar: Back to Basics: Thinking in Documents
PPTX
ETL for Pros: Getting Data Into MongoDB
PPTX
Intro to mongodb mongouk jun2010
PPTX
Mongo DB 102
PPTX
The Aggregation Framework
PDF
MongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
PPTX
Mongo Nosql CRUD Operations
PPTX
Webinar: Transitioning from SQL to MongoDB
ODP
MongoDB - javascript for your data
KEY
MongoDB Java Development - MongoBoston 2010
PPTX
Webinar: Exploring the Aggregation Framework
PPTX
Agg framework selectgroup feb2015 v2
PPTX
ETL for Pros: Getting Data Into MongoDB
PDF
Doing More with MongoDB Aggregation
PPTX
Mongo db – document oriented database
PDF
Omnibus database machine
PDF
Working with JSON Data in PostgreSQL vs. MongoDB
PPTX
Getting Started with Geospatial Data in MongoDB
PPTX
Introduction to MongoDB
Webinar: Back to Basics: Thinking in Documents
ETL for Pros: Getting Data Into MongoDB
Intro to mongodb mongouk jun2010
Mongo DB 102
The Aggregation Framework
MongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
Mongo Nosql CRUD Operations
Webinar: Transitioning from SQL to MongoDB
MongoDB - javascript for your data
MongoDB Java Development - MongoBoston 2010
Webinar: Exploring the Aggregation Framework
Agg framework selectgroup feb2015 v2
ETL for Pros: Getting Data Into MongoDB
Doing More with MongoDB Aggregation
Mongo db – document oriented database
Omnibus database machine
Working with JSON Data in PostgreSQL vs. MongoDB
Getting Started with Geospatial Data in MongoDB
Introduction to MongoDB
Ad

Similar to Introduction to MongoDB at IGDTUW (20)

PPTX
Webinar: What's new in the .NET Driver
PDF
RedisConf18 - Redis Memory Optimization
PPT
Building web applications with mongo db presentation
PDF
Building your first app with MongoDB
PDF
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
PDF
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
PPT
Mongo Web Apps: OSCON 2011
PPTX
MongoDB Schema Design: Practical Applications and Implications
PPTX
Introduction to MongoDB
PPTX
Dev Jumpstart: Build Your First App with MongoDB
PDF
Analytics with MongoDB Aggregation Framework and Hadoop Connector
PPTX
Eagle6 mongo dc revised
PPTX
Eagle6 Enterprise Situational Awareness
PDF
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
PDF
Simplifying & accelerating application development with MongoDB's intelligent...
PPTX
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
PDF
Superficial mongo db
PPTX
Mongo db
PDF
Practical JSON in MySQL 5.7 and Beyond
PPTX
Data Analytics with MongoDB - Jane Fine
Webinar: What's new in the .NET Driver
RedisConf18 - Redis Memory Optimization
Building web applications with mongo db presentation
Building your first app with MongoDB
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
Mongo Web Apps: OSCON 2011
MongoDB Schema Design: Practical Applications and Implications
Introduction to MongoDB
Dev Jumpstart: Build Your First App with MongoDB
Analytics with MongoDB Aggregation Framework and Hadoop Connector
Eagle6 mongo dc revised
Eagle6 Enterprise Situational Awareness
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
Simplifying & accelerating application development with MongoDB's intelligent...
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
Superficial mongo db
Mongo db
Practical JSON in MySQL 5.7 and Beyond
Data Analytics with MongoDB - Jane Fine
Ad

More from Ankur Raina (8)

PPTX
PyMongo for PyCon First Draft
PPTX
Mug17 gurgaon
PPTX
Ankur py mongo.pptx
PDF
Oracle SQL Basics by Ankur Raina
PPTX
Cloud computing
PDF
Sql project presentation
PPTX
Big data
PyMongo for PyCon First Draft
Mug17 gurgaon
Ankur py mongo.pptx
Oracle SQL Basics by Ankur Raina
Cloud computing
Sql project presentation
Big data

Recently uploaded (20)

PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPT
Teaching material agriculture food technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Cloud computing and distributed systems.
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Machine learning based COVID-19 study performance prediction
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Teaching material agriculture food technology
Dropbox Q2 2025 Financial Results & Investor Presentation
Cloud computing and distributed systems.
Spectral efficient network and resource selection model in 5G networks
Reach Out and Touch Someone: Haptics and Empathic Computing
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Big Data Technologies - Introduction.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
sap open course for s4hana steps from ECC to s4
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Assigned Numbers - 2025 - Bluetooth® Document
Machine learning based COVID-19 study performance prediction
Building Integrated photovoltaic BIPV_UPV.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Unlocking AI with Model Context Protocol (MCP)
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

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