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

PPT
Power shell object
PDF
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
ODP
2011 Mongo FR - Indexing in MongoDB
PPTX
Drupal7 dbtng
PDF
MongoDB With Style
PPTX
Indexing and Query Optimizer (Aaron Staple)
PDF
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
PDF
Building DSLs with Groovy
Power shell object
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
2011 Mongo FR - Indexing in MongoDB
Drupal7 dbtng
MongoDB With Style
Indexing and Query Optimizer (Aaron Staple)
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
Building DSLs with Groovy

What's hot (20)

PPT
Chris Mc Glothen Sql Portfolio
PPTX
Indexing and Query Optimization
PDF
Embedding a language into string interpolator
PDF
Python dictionary : past, present, future
PPTX
ETL for Pros: Getting Data Into MongoDB
PPT
2310 b 10
PDF
Functional es6
PDF
What do you mean, Backwards Compatibility?
PPTX
Data Governance with JSON Schema
PPTX
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
PPTX
MongoDB + Java - Everything you need to know
PDF
webScrapingFunctions
PDF
MongoDB .local Chicago 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
PDF
MongoDB .local Toronto 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
PDF
MongoDB World 2016: Deciphering .explain() Output
PPTX
Mongo db basic installation
PDF
Mongo indexes
PDF
Erlang for data ops
PDF
MongoDB Performance Tuning
PDF
Storing tree structures with MongoDB
Chris Mc Glothen Sql Portfolio
Indexing and Query Optimization
Embedding a language into string interpolator
Python dictionary : past, present, future
ETL for Pros: Getting Data Into MongoDB
2310 b 10
Functional es6
What do you mean, Backwards Compatibility?
Data Governance with JSON Schema
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
MongoDB + Java - Everything you need to know
webScrapingFunctions
MongoDB .local Chicago 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
MongoDB .local Toronto 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
MongoDB World 2016: Deciphering .explain() Output
Mongo db basic installation
Mongo indexes
Erlang for data ops
MongoDB Performance Tuning
Storing tree structures with MongoDB
Ad

Viewers also liked (10)

PDF
Gold in Oceans-EPSL
PDF
Main homepage
PDF
Blog English A2
PPTX
Phrasal Verbs
PDF
Christopher Johnson Bachelor's Thesis
PDF
Blog lenya topia
PDF
Executive Functioning Brief
PPTX
Ppt on maglev display
PDF
Python overview
Gold in Oceans-EPSL
Main homepage
Blog English A2
Phrasal Verbs
Christopher Johnson Bachelor's Thesis
Blog lenya topia
Executive Functioning Brief
Ppt on maglev display
Python overview
Ad

Similar to MongoDB (20)

PPTX
Mongo DB 102
PDF
Slide perkenalan dengan dasar MongoDB-query
PDF
MongoDB Aggregation Framework
PPTX
MongoDB Aggregation
PPTX
Webinar: General Technical Overview of MongoDB for Dev Teams
PDF
Dev Jumpstart: Build Your First App with MongoDB
PPTX
How to leverage what's new in MongoDB 3.6
PPTX
Query for json databases
PDF
An introduction into Spring Data
PPTX
MongoDB World 2018: Keynote
PPTX
Google apps script database abstraction exposed version
KEY
Schema Design with MongoDB
ZIP
CouchDB-Lucene
PDF
Data access 2.0? Please welcome: Spring Data!
PDF
MongoD Essentials
PPTX
Introduction to MongoDB and Workshop
PPTX
MongoDB Workshop.pptx computer science and engineering
PDF
Spray Json and MongoDB Queries: Insights and Simple Tricks.
PDF
Mongo Presentation by Metatagg Solutions
Mongo DB 102
Slide perkenalan dengan dasar MongoDB-query
MongoDB Aggregation Framework
MongoDB Aggregation
Webinar: General Technical Overview of MongoDB for Dev Teams
Dev Jumpstart: Build Your First App with MongoDB
How to leverage what's new in MongoDB 3.6
Query for json databases
An introduction into Spring Data
MongoDB World 2018: Keynote
Google apps script database abstraction exposed version
Schema Design with MongoDB
CouchDB-Lucene
Data access 2.0? Please welcome: Spring Data!
MongoD Essentials
Introduction to MongoDB and Workshop
MongoDB Workshop.pptx computer science and engineering
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Mongo Presentation by Metatagg Solutions

Recently uploaded (20)

PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
history of c programming in notes for students .pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
System and Network Administraation Chapter 3
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Transform Your Business with a Software ERP System
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
System and Network Administration Chapter 2
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
ai tools demonstartion for schools and inter college
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
wealthsignaloriginal-com-DS-text-... (1).pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
history of c programming in notes for students .pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
System and Network Administraation Chapter 3
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Operating system designcfffgfgggggggvggggggggg
Odoo Companies in India – Driving Business Transformation.pdf
How Creative Agencies Leverage Project Management Software.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
Transform Your Business with a Software ERP System
CHAPTER 2 - PM Management and IT Context
Wondershare Filmora 15 Crack With Activation Key [2025
Softaken Excel to vCard Converter Software.pdf
System and Network Administration Chapter 2
How to Choose the Right IT Partner for Your Business in Malaysia
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
ai tools demonstartion for schools and inter college
Internet Downloader Manager (IDM) Crack 6.42 Build 41

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>