SlideShare a Scribd company logo
Python with
MongoDB
What is mongoDB
Non Relational DB: It means it stores json in
document rather than table.
Schemaless
example:
{“first-name”: “jhon”, “last-name”:”smith”, “age”:32 }
{“first-name”: “jhon”, “last-name”:”smith”, “age”:32 ,
gender:”male”}
Why NoSQL?
Trend shows that NoSQL is used in big data in
real time application.
Some of the key Feature are :
Simple in Design
Supports Horizontal Scaling
Data Availability
NoSQL Database Available
Clusterpoint
Couchbase
CouchDB
MongoDB
etc.
Where mongoDB stands?
MongoDB doesn’t supports
Joins
Transaction across multiple collections.
But new version supports “Transaction”
Crud operation equivalent to RDBMS
Operations MongoDB RDBMS
Create Insert Insert
Read Find Select
Update Update Update
Delete Remove Delete
Compare terms in NoSQL / RDBMS
MongoDB hasn’t query language
Like SQL, MongoDB has no query language all
operation exists as method or functions
MongoDB Query
db.user.find()
This will get all the data from user collection
db.user.findOne()
It will get the first record from the user
collection
Command
Equivalent to where clause
db.user.find({“first_name” : “john”})
This will fetch all the data along with all col whose first_name is equal to john
db.user.find({“first_name” : “john”}, {“first_name” : true})
This will only get the first_name as a result set along with _id
db.user.find({“first_name” : “john”}, {“first_name”:true, “_id”: false})
This will exclude _id from the result se
Craeting a dummy data
for(i=0; i<1000;i++) { name = ["john", "smith",
"laura"]; for(j=0;j<3;j++){ db.student.insert
({"student_id": i, "stu_name":name[j], "score":
Math.round(Math.random()*100)}) } };
And in where clause
db.student.find({"stu_name":"smith", "score":90});
This will fetch all the records which have stu_name = smith and score=90
db.student.find({"stu_name":"smith", "score":90}, {"stu_name":true});
This will fetch all the records which have stu_name = smith and score=90 but
return only stu_name along with _id
Greater than Operator
command
Where clauses (< , >)
$gt , $gte, $lt and $lte Operator
db.student.find({"stu_name":"smith", "score": { $gt : 95}}, {"stu_name":true,
score:true});
Fetch the data whose score is greater than 95
db.student.find({"stu_name":"smith", "score": { $gt : 95, $lt : 98}}, {"stu_name":
true, score:true});
Fetch the data whose score is greater than 95 but less than 98
OR operator
db.student.find({$or: [{"score":90}, {"score" :
80}]});
This will fetch the data whose score is either 90
or 80.
Nature of polymorphism
db.student.find({"stu_name" : {$lt : "l"}, "score" : {$gt : 98}})
This will fetch the student name less than “l”
db.student.find({"stu_name" : {$lt : 30}})
Note : tightly bound within the data type
Command [Regex , exists, type ]
db.student.find({"stu_name" : {$regex : "ih"}})
db.student.find({"stu_name" : {$exists : true}})
db.student.find({"stu_name" : {$type : 1}})
It will fetch the data of number type
db.student.find({"stu_name" : {$type : 2}})
It will fetch the data of string type
Seach in Array
db.student.insert({"stu_name" : 11, "subject" :["hindi", "english", "math"]})
db.student.insert({"stu_name" : 22, "subject" :["math", "german", "spanish"]})
db.student.insert({"stu_name" : 22, "subject" :["math", "german", 100]})
db.student.find({"subject" : "hindi"})
db.student.find({"subject" : 100})
(Another type of polymorphism)
Continue...
db.student.find({"subject" : {$all : ["hindi", "english" ]}})
Fetch the data which contains both in subject array
db.student.find({"subject" : {$in : ["hindi", "math" ]}})
Return the data set which satisfy either of the value
Cursor
>cur = db.student.find({"subject" : {$in : ["hindi", "math" ]}}), null;
null
> cur.hasNext()
true
> cur.next()
{
"_id" : ObjectId("54421c362d3b0ea3d1c08eb2"),
"stu_name" : 11,
"subject" : [
"hindi",
"english",
"math"
]
}
count the number of document
> cur = db.student.find({"subject" : {$in : ["hindi", "math" ]}});
{ "_id" : ObjectId("54421c362d3b0ea3d1c08eb2"), "stu_name" : 11, "subject" : [
"hindi", "english", "math" ] }
{ "_id" : ObjectId("54421c532d3b0ea3d1c08eb3"), "stu_name" : 22, "subject" : [
"math", "german", "spanish" ] }
{ "_id" : ObjectId("54421c982d3b0ea3d1c08eb4"), "stu_name" : 22, "subject" : [
"math", "german", 100 ] }
> cur = db.student.count({"subject" : {$in : ["hindi", "math" ]}});
3
>
Aggregation
Simple GroupBy Clause
URL : https://www.youtube.com/watch?
v=3lEpnMcfpCs
Command
Count
> db.student.aggregate([ {$group: { _id: "$stu_name", num_student: {$sum : 1}}}])
{
"result" : [
{
"_id" : 22,
"num_student" : 2
},
{
"_id" : 40,
"num_student" : 1
},
{
"_id" : 30,
"num_student" : 1
Sum with group
SUM on Score
> db.student.aggregate([ {$group: { _id: "$stu_name", num_student: {$sum : “$score”}}}])
Sort on score :
db.student.aggregate([ {$group: { _id: "$stu_name", num_student1: {$sum : "$score"}}}, {$sort :
{num_student1 : 1}}])
db.student.aggregate( {$match : {"stu_name" : "smith"}}, { $group: {_id : "$stu_name" , total : {$sum :
1}}} )
> db.student.aggregate([ {$group: { _id: "$stu_name", num_student: {$sum : “$score”}}}], {explain :
Thanks You
Special Thanks To ICREON.
Your custom link is:
http://webchat.freenode.net?channels=python-dilli-meetup-group&uio=d4
<iframe src="http://webchat.freenode.net?
channels=python-dilli-meetup-group&uio=d4" width="647"
height="400"></iframe>
MongoDB

More Related Content

What's hot (20)

PPT
Chris Mc Glothen Sql Portfolio
clmcglothen
 
PPTX
Indexing and Query Optimization
MongoDB
 
PDF
Embedding a language into string interpolator
Michael Limansky
 
PDF
Python dictionary : past, present, future
delimitry
 
PPTX
ETL for Pros: Getting Data Into MongoDB
MongoDB
 
PPT
2310 b 10
Krazy Koder
 
PDF
Functional es6
Natalia Zaslavskaya
 
PDF
What do you mean, Backwards Compatibility?
Trisha Gee
 
PPTX
Data Governance with JSON Schema
MongoDB
 
PPTX
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
MongoDB
 
PPTX
MongoDB + Java - Everything you need to know
Norberto Leite
 
PDF
webScrapingFunctions
Hellen Gakuruh
 
PDF
MongoDB .local Chicago 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
MongoDB
 
PDF
MongoDB .local Toronto 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
MongoDB
 
PDF
MongoDB World 2016: Deciphering .explain() Output
MongoDB
 
PPTX
Mongo db basic installation
Kishor Parkhe
 
PDF
Mongo indexes
Mehmet Çetin
 
PDF
Erlang for data ops
mnacos
 
PDF
MongoDB Performance Tuning
Puneet Behl
 
PDF
Storing tree structures with MongoDB
Vyacheslav
 
Chris Mc Glothen Sql Portfolio
clmcglothen
 
Indexing and Query Optimization
MongoDB
 
Embedding a language into string interpolator
Michael Limansky
 
Python dictionary : past, present, future
delimitry
 
ETL for Pros: Getting Data Into MongoDB
MongoDB
 
2310 b 10
Krazy Koder
 
Functional es6
Natalia Zaslavskaya
 
What do you mean, Backwards Compatibility?
Trisha Gee
 
Data Governance with JSON Schema
MongoDB
 
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
MongoDB
 
MongoDB + Java - Everything you need to know
Norberto Leite
 
webScrapingFunctions
Hellen Gakuruh
 
MongoDB .local Chicago 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
MongoDB
 
MongoDB .local Toronto 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
MongoDB
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB
 
Mongo db basic installation
Kishor Parkhe
 
Mongo indexes
Mehmet Çetin
 
Erlang for data ops
mnacos
 
MongoDB Performance Tuning
Puneet Behl
 
Storing tree structures with MongoDB
Vyacheslav
 

Viewers also liked (10)

PDF
Gold in Oceans-EPSL
Ross Large
 
PDF
Main homepage
YourBody Changing.Com
 
PDF
Blog English A2
Letopiac
 
PPTX
Phrasal Verbs
Letopiac
 
PDF
Christopher Johnson Bachelor's Thesis
BagpipesJohnson
 
PDF
Blog lenya topia
Letopiac
 
PDF
Executive Functioning Brief
Sarah Barrett
 
PPTX
Ppt on maglev display
Nihar Ranjan Swain
 
PDF
Python overview
Hemant Kumar Tiwary
 
Gold in Oceans-EPSL
Ross Large
 
Main homepage
YourBody Changing.Com
 
Blog English A2
Letopiac
 
Phrasal Verbs
Letopiac
 
Christopher Johnson Bachelor's Thesis
BagpipesJohnson
 
Blog lenya topia
Letopiac
 
Executive Functioning Brief
Sarah Barrett
 
Ppt on maglev display
Nihar Ranjan Swain
 
Python overview
Hemant Kumar Tiwary
 
Ad

Similar to MongoDB (20)

PPTX
Mongo DB 102
Abhijeet Vaikar
 
PDF
Slide perkenalan dengan dasar MongoDB-query
amazaza49
 
PDF
MongoDB Aggregation Framework
Caserta
 
PPTX
MongoDB Aggregation
Amit Ghosh
 
PPTX
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
 
PDF
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
PPTX
How to leverage what's new in MongoDB 3.6
Maxime Beugnet
 
PPTX
Query for json databases
Binh Le
 
PDF
An introduction into Spring Data
Oliver Gierke
 
PPTX
MongoDB World 2018: Keynote
MongoDB
 
PPTX
Google apps script database abstraction exposed version
Bruce McPherson
 
KEY
Schema Design with MongoDB
rogerbodamer
 
ZIP
CouchDB-Lucene
Martin Rehfeld
 
PDF
Data access 2.0? Please welcome: Spring Data!
Oliver Gierke
 
PDF
MongoD Essentials
zahid-mian
 
PPTX
Introduction to MongoDB and Workshop
AhmedabadJavaMeetup
 
PPTX
MongoDB Workshop.pptx computer science and engineering
sanjay21042
 
PDF
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Andrii Lashchenko
 
PDF
Mongo Presentation by Metatagg Solutions
Metatagg Solutions
 
Mongo DB 102
Abhijeet Vaikar
 
Slide perkenalan dengan dasar MongoDB-query
amazaza49
 
MongoDB Aggregation Framework
Caserta
 
MongoDB Aggregation
Amit Ghosh
 
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
 
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
How to leverage what's new in MongoDB 3.6
Maxime Beugnet
 
Query for json databases
Binh Le
 
An introduction into Spring Data
Oliver Gierke
 
MongoDB World 2018: Keynote
MongoDB
 
Google apps script database abstraction exposed version
Bruce McPherson
 
Schema Design with MongoDB
rogerbodamer
 
CouchDB-Lucene
Martin Rehfeld
 
Data access 2.0? Please welcome: Spring Data!
Oliver Gierke
 
MongoD Essentials
zahid-mian
 
Introduction to MongoDB and Workshop
AhmedabadJavaMeetup
 
MongoDB Workshop.pptx computer science and engineering
sanjay21042
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Andrii Lashchenko
 
Mongo Presentation by Metatagg Solutions
Metatagg Solutions
 
Ad

Recently uploaded (20)

PPT
Brief History of Python by Learning Python in three hours
adanechb21
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PDF
How to Download and Install ADT (ABAP Development Tools) for Eclipse IDE | SA...
SAP Vista, an A L T Z E N Company
 
PPTX
Processing with Claim Management Automation Solutions
Insurance Tech Services
 
PPTX
Online Contractor Induction and Safety Induction Training Software
SHEQ Network Limited
 
PDF
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PPTX
Farrell__10e_ch04_PowerPoint.pptx Programming Logic and Design slides
bashnahara11
 
PPTX
Employee salary prediction using Machine learning Project template.ppt
bhanuk27082004
 
PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
PDF
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
PPTX
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
PDF
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
PPTX
SAP Public Cloud PPT , SAP PPT, Public Cloud PPT
sonawanekundan2024
 
PDF
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 
PDF
AI Image Enhancer: Revolutionizing Visual Quality”
docmasoom
 
PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
Brief History of Python by Learning Python in three hours
adanechb21
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
How to Download and Install ADT (ABAP Development Tools) for Eclipse IDE | SA...
SAP Vista, an A L T Z E N Company
 
Processing with Claim Management Automation Solutions
Insurance Tech Services
 
Online Contractor Induction and Safety Induction Training Software
SHEQ Network Limited
 
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
Farrell__10e_ch04_PowerPoint.pptx Programming Logic and Design slides
bashnahara11
 
Employee salary prediction using Machine learning Project template.ppt
bhanuk27082004
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
SAP Public Cloud PPT , SAP PPT, Public Cloud PPT
sonawanekundan2024
 
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 
AI Image Enhancer: Revolutionizing Visual Quality”
docmasoom
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 

MongoDB

  • 2. What is mongoDB Non Relational DB: It means it stores json in document rather than table. Schemaless example: {“first-name”: “jhon”, “last-name”:”smith”, “age”:32 } {“first-name”: “jhon”, “last-name”:”smith”, “age”:32 , gender:”male”}
  • 3. Why NoSQL? Trend shows that NoSQL is used in big data in real time application. Some of the key Feature are : Simple in Design Supports Horizontal Scaling Data Availability
  • 6. MongoDB doesn’t supports Joins Transaction across multiple collections. But new version supports “Transaction”
  • 7. Crud operation equivalent to RDBMS Operations MongoDB RDBMS Create Insert Insert Read Find Select Update Update Update Delete Remove Delete
  • 8. Compare terms in NoSQL / RDBMS
  • 9. MongoDB hasn’t query language Like SQL, MongoDB has no query language all operation exists as method or functions
  • 10. MongoDB Query db.user.find() This will get all the data from user collection db.user.findOne() It will get the first record from the user collection
  • 11. Command Equivalent to where clause db.user.find({“first_name” : “john”}) This will fetch all the data along with all col whose first_name is equal to john db.user.find({“first_name” : “john”}, {“first_name” : true}) This will only get the first_name as a result set along with _id db.user.find({“first_name” : “john”}, {“first_name”:true, “_id”: false}) This will exclude _id from the result se
  • 12. Craeting a dummy data for(i=0; i<1000;i++) { name = ["john", "smith", "laura"]; for(j=0;j<3;j++){ db.student.insert ({"student_id": i, "stu_name":name[j], "score": Math.round(Math.random()*100)}) } };
  • 13. And in where clause db.student.find({"stu_name":"smith", "score":90}); This will fetch all the records which have stu_name = smith and score=90 db.student.find({"stu_name":"smith", "score":90}, {"stu_name":true}); This will fetch all the records which have stu_name = smith and score=90 but return only stu_name along with _id Greater than Operator command
  • 14. Where clauses (< , >) $gt , $gte, $lt and $lte Operator db.student.find({"stu_name":"smith", "score": { $gt : 95}}, {"stu_name":true, score:true}); Fetch the data whose score is greater than 95 db.student.find({"stu_name":"smith", "score": { $gt : 95, $lt : 98}}, {"stu_name": true, score:true}); Fetch the data whose score is greater than 95 but less than 98
  • 15. OR operator db.student.find({$or: [{"score":90}, {"score" : 80}]}); This will fetch the data whose score is either 90 or 80.
  • 16. Nature of polymorphism db.student.find({"stu_name" : {$lt : "l"}, "score" : {$gt : 98}}) This will fetch the student name less than “l” db.student.find({"stu_name" : {$lt : 30}}) Note : tightly bound within the data type
  • 17. Command [Regex , exists, type ] db.student.find({"stu_name" : {$regex : "ih"}}) db.student.find({"stu_name" : {$exists : true}}) db.student.find({"stu_name" : {$type : 1}}) It will fetch the data of number type db.student.find({"stu_name" : {$type : 2}}) It will fetch the data of string type
  • 18. Seach in Array db.student.insert({"stu_name" : 11, "subject" :["hindi", "english", "math"]}) db.student.insert({"stu_name" : 22, "subject" :["math", "german", "spanish"]}) db.student.insert({"stu_name" : 22, "subject" :["math", "german", 100]}) db.student.find({"subject" : "hindi"}) db.student.find({"subject" : 100}) (Another type of polymorphism)
  • 19. Continue... db.student.find({"subject" : {$all : ["hindi", "english" ]}}) Fetch the data which contains both in subject array db.student.find({"subject" : {$in : ["hindi", "math" ]}}) Return the data set which satisfy either of the value
  • 20. Cursor >cur = db.student.find({"subject" : {$in : ["hindi", "math" ]}}), null; null > cur.hasNext() true > cur.next() { "_id" : ObjectId("54421c362d3b0ea3d1c08eb2"), "stu_name" : 11, "subject" : [ "hindi", "english", "math" ] }
  • 21. count the number of document > cur = db.student.find({"subject" : {$in : ["hindi", "math" ]}}); { "_id" : ObjectId("54421c362d3b0ea3d1c08eb2"), "stu_name" : 11, "subject" : [ "hindi", "english", "math" ] } { "_id" : ObjectId("54421c532d3b0ea3d1c08eb3"), "stu_name" : 22, "subject" : [ "math", "german", "spanish" ] } { "_id" : ObjectId("54421c982d3b0ea3d1c08eb4"), "stu_name" : 22, "subject" : [ "math", "german", 100 ] } > cur = db.student.count({"subject" : {$in : ["hindi", "math" ]}}); 3 >
  • 22. Aggregation Simple GroupBy Clause URL : https://www.youtube.com/watch? v=3lEpnMcfpCs
  • 23. Command Count > db.student.aggregate([ {$group: { _id: "$stu_name", num_student: {$sum : 1}}}]) { "result" : [ { "_id" : 22, "num_student" : 2 }, { "_id" : 40, "num_student" : 1 }, { "_id" : 30, "num_student" : 1
  • 24. Sum with group SUM on Score > db.student.aggregate([ {$group: { _id: "$stu_name", num_student: {$sum : “$score”}}}]) Sort on score : db.student.aggregate([ {$group: { _id: "$stu_name", num_student1: {$sum : "$score"}}}, {$sort : {num_student1 : 1}}]) db.student.aggregate( {$match : {"stu_name" : "smith"}}, { $group: {_id : "$stu_name" , total : {$sum : 1}}} ) > db.student.aggregate([ {$group: { _id: "$stu_name", num_student: {$sum : “$score”}}}], {explain :
  • 25. Thanks You Special Thanks To ICREON. Your custom link is: http://webchat.freenode.net?channels=python-dilli-meetup-group&uio=d4 <iframe src="http://webchat.freenode.net? channels=python-dilli-meetup-group&uio=d4" width="647" height="400"></iframe>