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
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
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
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

What's hot

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 jun2010Skills 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 2010Eliot 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 databaseWojciech 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
 

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
 
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
 
Intro to mongodb mongouk jun2010
Intro to mongodb mongouk jun2010Intro to mongodb mongouk jun2010
Intro to mongodb mongouk jun2010
 
Mongo DB 102
Mongo DB 102Mongo DB 102
Mongo DB 102
 
The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation Framework
 
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
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD OperationsMongo Nosql CRUD Operations
Mongo Nosql CRUD Operations
 
Webinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDBWebinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDB
 
MongoDB - javascript for your data
MongoDB - javascript for your dataMongoDB - javascript for your data
MongoDB - javascript for your data
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
 
Webinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation FrameworkWebinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation Framework
 
Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2
 
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
 
Doing More with MongoDB Aggregation
Doing More with MongoDB AggregationDoing More with MongoDB Aggregation
Doing More with MongoDB Aggregation
 
Mongo db – document oriented database
Mongo db – document oriented databaseMongo db – document oriented database
Mongo db – document oriented database
 
Omnibus database machine
Omnibus database machineOmnibus database machine
Omnibus database machine
 
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
 
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
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 

Similar to Introduction to MongoDB at IGDTUW

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 presentationMurat Ç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 revisedMongoDB
 
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 dbDaeMyung 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
 

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
 
RedisConf18 - Redis Memory Optimization
RedisConf18 - Redis Memory OptimizationRedisConf18 - Redis Memory Optimization
RedisConf18 - Redis Memory Optimization
 
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
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
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.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
 
Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011
 
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
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to 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
 
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
 
Eagle6 mongo dc revised
Eagle6 mongo dc revisedEagle6 mongo dc revised
Eagle6 mongo dc revised
 
Eagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessEagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational Awareness
 
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
 
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...
 
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...
 
Superficial mongo db
Superficial mongo dbSuperficial mongo db
Superficial mongo db
 
Mongo db
Mongo dbMongo db
Mongo db
 
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
 
Data Analytics with MongoDB - Jane Fine
Data Analytics with MongoDB - Jane FineData Analytics with MongoDB - Jane Fine
Data Analytics with MongoDB - Jane Fine
 

More from Ankur Raina

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
 
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
 

More from Ankur Raina (8)

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

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 

Introduction to MongoDB at IGDTUW

  • 1. Indira Gandhi Delhi Technical University for Women Speakers: ● Ankur Raina ( ankur.raina@mongodb.com ) ● Pooja Gupta ( pooja.gupta@mongodb.com )
  • 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
  • 23.
  • 24.
  • 25. Citizen Database Banking Application Sim Card Subscribers Gas Connection Subscription Biometric Details Example
  • 33.
  • 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
  • 35.
  • 36.
  • 37.
  • 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