SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
Starting with MongoDB

     Murad Kamalov
Estonia
Tallinn             Tartu
Finland
Helsinki
Dunedin
DoThinger.com
                  @DoThinger

• Do things together with people nearby
Intro to MongoDB
•   Schemaless
•   Supports replication and shardling
•   Indexing
•   File storage
•   Aggregation (Map/Reduce)
•   Geospacial queries
Benefits of MongoDB
• Great choice for agile projects
   – no schema = no limitations
   – ease of use
• Scalability & high availability
   – thanks to shardling and replication
• Failover and automatic recovery
Main Concepts
• Database is set of collections
• Collection is like a table in MySQL (e.g events
  collection)
• Document belongs to a collection, like row in
  MySQL, unlike in MySQL documents in same
  collection can have different structure
• Documents store fields as key-value pairs, where
  value can be basic data type, another document
  or array
• Data is stored in JSON format (serialized as BSON)
Example
• Inserting document into events collection:
    > db.events.insert({
       “title” : “CodeCraft Meeting”,
       “description” : “CodeCraft meeting in Dunedin on Tuesday evening”,
       “start_datetime” : ISODate(“2012-04-03T17:30:00”),
       “category” : “social”
     })

    > db.events.insert({
       “title” : “CodeCraft Meeting 2”,
       “description” : “CodeCraft meeting in Dunedin on Tuesday evening”,
       “start_datetime” : ISODate(“2012-05-03 17:30:00”),
       “category” : “social”,
       “participants” : 50
     })

•   When Inserting, indexed field _id is created automatically for each inserted
    document
Embedded Documents
• Linking versus Embedding
   – e.g instead of creating separate collection for comments,
     just embed comments in events collection
   – MongoDB doesn’t support JOINs = use embedding
> db.events.insert({
   “title” : “Title”,
   “description” : “Description”,
   “start_date” : ISODate(“2012-04-03T17:30:00”),
   “category” : “social”,
   “comments”: [
     {“author”: <user_id>, “comment” :“My First Comment”},
     {“author”: <user_id>, “comment”: “My Second Comment”}]
  })
Querying
• Can be done in many various ways in MongoDB
> db.events.find({“title”: “CodeCraft Meeting”})
> {“_id”: ObjectId(41234351451345), “title” : “CodeCraft
   Meeting”, “description” : “Description”, “start_datetime” :
   ISODate(“2012-04-03T17:30:00”), “category” : “social”}

> db.events.find({“start_datetime” : {$gte : ISODate(“2012-
   04-01T00:00:00”)}})
> {“_id”: ObjectId(41234351451345), “title” : “CodeCraft
   Meeting”, “description” : “Description”, “start_datetime”
   : ISODate(“2012-04-03T17:30:00”), “category” : “social”}
  {“_id”: ObjectId(41226542345234), “title” : “CodeCraft
   Meeting 2”, “description” : “Description”, “start_datetime”
   : ISODate(“2012-05-03T17:30:00”), “category” : “social”,
   “participants” : 50}
Updates
• Replacing the entire document
>   db.events.update({“_id”: ObjectId(41234351451345)},
    {“title” : “New Title”,
     “description” : “Description”,
     “start_date” : ISODate(“2012-04-03T17:30:00”),
     “category” : “social”,
     “comments”: [
       {“author”: <user_id>, “comment” :“My First Comment”},
       {“author”: <user_id>, “comment”: “My Second Comment”
    })

• Atomic updates
>   db.events.update({“_id”:ObjectId(41234351451345)},
     {$set : {“title”: {“New Title”}}}
    )
Updates (2)
• Pushing Elements to Arrays
>   db.events.update({“_id”:ObjectId(41234351451345)},
    {$push : {“comments”: {“author”: <user_id>, “comment”: “My
    Third Comment”}}})

> {“title” : “Title”,
   “description” : “Description”,
   “start_date” : ISODate(“2012-04-03T17:30:00”),
   “category” : “social”,
   “comments”: [
     {“author”: <user_id>, “comment” :“My First Comment”},
     {“author”: <user_id>, “comment”: “My Second Comment”},
     {“author”: <user_id>, “comment”: “My Third Comment”}]
  })
Geospatial queries
• MongoDB has build-in support for geospacial queries
> db.events.insert({
   “title” : “Title”,
   “description” : “Description”,
   “start_datetime” : ISODate(“2012-04-03T17:30:00”),
   “category” : “social”,
   “location” : [30, 30]
  })
> db.events.ensureIndex({“location” : “2d”})
> db.events.find({“location”: {$near: [28,28],
  $maxDistance: 5}})
Files (GridFS)
• In MySQL it’s a bad practice to save large binary
  files into the database
• In MongoDB it’s a bad practice NOT TO save large
  files into the database.
• MongoDB splits saved files into chunks, which
  allows querying of only necessary parts of the
  binary files
• Example(pymongo library)
  >>> fs = gridfs.GridFs(db_name)
  >>> filename = fs.put(“Example file data”)
  >>> file_data = fs.get(filename).read()
Map/Reduce
db.events.mapReduce(map_func, reduce_func,
{out: “out_collection”})

• map_func and reduce_func are written       in
  JavaScript
• Output of reduce_func is stored in output
  collection
Language Drivers
• Different language drivers for MongoDB provide different levels of
  abstraction
    – PyMongo (similar to mongo shell) vs MongoEngine (ORM-like)
class Event(mongoengine.Document):
   title = StringField()
   description = StringField()
   start_date = DateTimeField(default=datetime.now)
   category = StringField()
   comments = ListField(EmbeddedDocumentField(Comment))

#querying
event = Events.objects(title = “Title”)

#adding comments
event.update(push__comments = comment)
Thank You!

 Questions?

Más contenido relacionado

La actualidad más candente

MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for BeginnersEnoch Joshua
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDBrogerbodamer
 
User Data Management with MongoDB
User Data Management with MongoDB User Data Management with MongoDB
User Data Management with MongoDB MongoDB
 
Socialite, the Open Source Status Feed Part 2: Managing the Social Graph
Socialite, the Open Source Status Feed Part 2: Managing the Social GraphSocialite, the Open Source Status Feed Part 2: Managing the Social Graph
Socialite, the Open Source Status Feed Part 2: Managing the Social GraphMongoDB
 
ENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQL
ENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQLENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQL
ENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQLHoracio Gonzalez
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleMongoDB
 
ENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQL
ENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQLENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQL
ENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQLHoracio Gonzalez
 
Mongo db – document oriented database
Mongo db – document oriented databaseMongo db – document oriented database
Mongo db – document oriented databaseWojciech Sznapka
 
Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.Ravi Teja
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMetatagg Solutions
 
Socialite, the Open Source Status Feed Part 3: Scaling the Data Feed
Socialite, the Open Source Status Feed Part 3: Scaling the Data FeedSocialite, the Open Source Status Feed Part 3: Scaling the Data Feed
Socialite, the Open Source Status Feed Part 3: Scaling the Data FeedMongoDB
 
PhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHPPhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHPichikaway
 
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLBack to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLMongoDB
 
MongoDB - A Document NoSQL Database
MongoDB - A Document NoSQL DatabaseMongoDB - A Document NoSQL Database
MongoDB - A Document NoSQL DatabaseRuben Inoto Soto
 
Socialite, the Open Source Status Feed
Socialite, the Open Source Status FeedSocialite, the Open Source Status Feed
Socialite, the Open Source Status FeedMongoDB
 

La actualidad más candente (20)

MongoDb and NoSQL
MongoDb and NoSQLMongoDb and NoSQL
MongoDb and NoSQL
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
MongoDB at GUL
MongoDB at GULMongoDB at GUL
MongoDB at GUL
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDB
 
User Data Management with MongoDB
User Data Management with MongoDB User Data Management with MongoDB
User Data Management with MongoDB
 
Socialite, the Open Source Status Feed Part 2: Managing the Social Graph
Socialite, the Open Source Status Feed Part 2: Managing the Social GraphSocialite, the Open Source Status Feed Part 2: Managing the Social Graph
Socialite, the Open Source Status Feed Part 2: Managing the Social Graph
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
ENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQL
ENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQLENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQL
ENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQL
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
 
ENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQL
ENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQLENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQL
ENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQL
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mongo db – document oriented database
Mongo db – document oriented databaseMongo db – document oriented database
Mongo db – document oriented database
 
Mongo DB 102
Mongo DB 102Mongo DB 102
Mongo DB 102
 
Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg Solutions
 
Socialite, the Open Source Status Feed Part 3: Scaling the Data Feed
Socialite, the Open Source Status Feed Part 3: Scaling the Data FeedSocialite, the Open Source Status Feed Part 3: Scaling the Data Feed
Socialite, the Open Source Status Feed Part 3: Scaling the Data Feed
 
PhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHPPhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHP
 
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLBack to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQL
 
MongoDB - A Document NoSQL Database
MongoDB - A Document NoSQL DatabaseMongoDB - A Document NoSQL Database
MongoDB - A Document NoSQL Database
 
Socialite, the Open Source Status Feed
Socialite, the Open Source Status FeedSocialite, the Open Source Status Feed
Socialite, the Open Source Status Feed
 

Destacado

Prueba Turismo Clase
Prueba Turismo Clase Prueba Turismo Clase
Prueba Turismo Clase Sermaldo
 
What you did last summer?
What you did last summer?What you did last summer?
What you did last summer?DoThinger
 
Professional Qualifications - Darin Janecek
Professional Qualifications - Darin JanecekProfessional Qualifications - Darin Janecek
Professional Qualifications - Darin JanecekDarin Janecek
 
Presskit "Girotondo" VENEZIA
Presskit "Girotondo" VENEZIAPresskit "Girotondo" VENEZIA
Presskit "Girotondo" VENEZIAkaspar2012
 
IL MUCCHIO - KASPAR HAUSER
IL MUCCHIO - KASPAR HAUSERIL MUCCHIO - KASPAR HAUSER
IL MUCCHIO - KASPAR HAUSERkaspar2012
 
VENEZIA a ROMA - programma 2012
VENEZIA a ROMA - programma 2012VENEZIA a ROMA - programma 2012
VENEZIA a ROMA - programma 2012kaspar2012
 
Het nwe leren ooud pers
Het nwe leren ooud persHet nwe leren ooud pers
Het nwe leren ooud persAdri de Gans
 
CINECRITICA MAGAZINE: SPECIALE sù DAVIDE MANULI
CINECRITICA MAGAZINE: SPECIALE sù DAVIDE MANULICINECRITICA MAGAZINE: SPECIALE sù DAVIDE MANULI
CINECRITICA MAGAZINE: SPECIALE sù DAVIDE MANULIkaspar2012
 
'Alias' Kaspar Hauser - Il Manifesto
'Alias' Kaspar Hauser - Il Manifesto'Alias' Kaspar Hauser - Il Manifesto
'Alias' Kaspar Hauser - Il Manifestokaspar2012
 
Power point slides_chapter_03
Power point slides_chapter_03Power point slides_chapter_03
Power point slides_chapter_03Surbhi Jain
 

Destacado (14)

Prueba Turismo Clase
Prueba Turismo Clase Prueba Turismo Clase
Prueba Turismo Clase
 
What you did last summer?
What you did last summer?What you did last summer?
What you did last summer?
 
Ncp overview april 2012
Ncp overview april 2012Ncp overview april 2012
Ncp overview april 2012
 
Professional Qualifications - Darin Janecek
Professional Qualifications - Darin JanecekProfessional Qualifications - Darin Janecek
Professional Qualifications - Darin Janecek
 
Presskit "Girotondo" VENEZIA
Presskit "Girotondo" VENEZIAPresskit "Girotondo" VENEZIA
Presskit "Girotondo" VENEZIA
 
GallupReport
GallupReportGallupReport
GallupReport
 
IL MUCCHIO - KASPAR HAUSER
IL MUCCHIO - KASPAR HAUSERIL MUCCHIO - KASPAR HAUSER
IL MUCCHIO - KASPAR HAUSER
 
Marketing management
Marketing managementMarketing management
Marketing management
 
VENEZIA a ROMA - programma 2012
VENEZIA a ROMA - programma 2012VENEZIA a ROMA - programma 2012
VENEZIA a ROMA - programma 2012
 
Het nwe leren ooud pers
Het nwe leren ooud persHet nwe leren ooud pers
Het nwe leren ooud pers
 
CINECRITICA MAGAZINE: SPECIALE sù DAVIDE MANULI
CINECRITICA MAGAZINE: SPECIALE sù DAVIDE MANULICINECRITICA MAGAZINE: SPECIALE sù DAVIDE MANULI
CINECRITICA MAGAZINE: SPECIALE sù DAVIDE MANULI
 
'Alias' Kaspar Hauser - Il Manifesto
'Alias' Kaspar Hauser - Il Manifesto'Alias' Kaspar Hauser - Il Manifesto
'Alias' Kaspar Hauser - Il Manifesto
 
Power point slides_chapter_03
Power point slides_chapter_03Power point slides_chapter_03
Power point slides_chapter_03
 
Skrip mc
Skrip mcSkrip mc
Skrip mc
 

Similar a Starting with MongoDB

Mongodb intro
Mongodb introMongodb intro
Mongodb introchristkv
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDBMongoDB
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)Uwe Printz
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data ModelingDATAVERSITY
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsMongoDB
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling rogerbodamer
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDBNorberto Leite
 
Building your first app with mongo db
Building your first app with mongo dbBuilding your first app with mongo db
Building your first app with mongo dbMongoDB
 
2012 mongo db_bangalore_roadmap_new
2012 mongo db_bangalore_roadmap_new2012 mongo db_bangalore_roadmap_new
2012 mongo db_bangalore_roadmap_newMongoDB
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDBNate Abele
 
Marc s01 e02-crud-database
Marc s01 e02-crud-databaseMarc s01 e02-crud-database
Marc s01 e02-crud-databaseMongoDB
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...MongoDB
 
Schema design
Schema designSchema design
Schema designchristkv
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHPichikaway
 
MongoDB NYC Python
MongoDB NYC PythonMongoDB NYC Python
MongoDB NYC PythonMike Dirolf
 
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 MongoDBMongoDB
 
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 LawleyNETWAYS
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBAlex Bilbie
 

Similar a Starting with MongoDB (20)

Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
 
The emerging world of mongo db csp
The emerging world of mongo db   cspThe emerging world of mongo db   csp
The emerging world of mongo db csp
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
Building your first app with mongo db
Building your first app with mongo dbBuilding your first app with mongo db
Building your first app with mongo db
 
2012 mongo db_bangalore_roadmap_new
2012 mongo db_bangalore_roadmap_new2012 mongo db_bangalore_roadmap_new
2012 mongo db_bangalore_roadmap_new
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
 
Marc s01 e02-crud-database
Marc s01 e02-crud-databaseMarc s01 e02-crud-database
Marc s01 e02-crud-database
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
 
Schema design
Schema designSchema design
Schema design
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHP
 
MongoDB NYC Python
MongoDB NYC PythonMongoDB NYC Python
MongoDB NYC Python
 
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
 
Querying mongo db
Querying mongo dbQuerying mongo db
Querying mongo db
 
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
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 

Último

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Último (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Starting with MongoDB

  • 1. Starting with MongoDB Murad Kamalov
  • 5. DoThinger.com @DoThinger • Do things together with people nearby
  • 6. Intro to MongoDB • Schemaless • Supports replication and shardling • Indexing • File storage • Aggregation (Map/Reduce) • Geospacial queries
  • 7. Benefits of MongoDB • Great choice for agile projects – no schema = no limitations – ease of use • Scalability & high availability – thanks to shardling and replication • Failover and automatic recovery
  • 8. Main Concepts • Database is set of collections • Collection is like a table in MySQL (e.g events collection) • Document belongs to a collection, like row in MySQL, unlike in MySQL documents in same collection can have different structure • Documents store fields as key-value pairs, where value can be basic data type, another document or array • Data is stored in JSON format (serialized as BSON)
  • 9. Example • Inserting document into events collection: > db.events.insert({ “title” : “CodeCraft Meeting”, “description” : “CodeCraft meeting in Dunedin on Tuesday evening”, “start_datetime” : ISODate(“2012-04-03T17:30:00”), “category” : “social” }) > db.events.insert({ “title” : “CodeCraft Meeting 2”, “description” : “CodeCraft meeting in Dunedin on Tuesday evening”, “start_datetime” : ISODate(“2012-05-03 17:30:00”), “category” : “social”, “participants” : 50 }) • When Inserting, indexed field _id is created automatically for each inserted document
  • 10. Embedded Documents • Linking versus Embedding – e.g instead of creating separate collection for comments, just embed comments in events collection – MongoDB doesn’t support JOINs = use embedding > db.events.insert({ “title” : “Title”, “description” : “Description”, “start_date” : ISODate(“2012-04-03T17:30:00”), “category” : “social”, “comments”: [ {“author”: <user_id>, “comment” :“My First Comment”}, {“author”: <user_id>, “comment”: “My Second Comment”}] })
  • 11. Querying • Can be done in many various ways in MongoDB > db.events.find({“title”: “CodeCraft Meeting”}) > {“_id”: ObjectId(41234351451345), “title” : “CodeCraft Meeting”, “description” : “Description”, “start_datetime” : ISODate(“2012-04-03T17:30:00”), “category” : “social”} > db.events.find({“start_datetime” : {$gte : ISODate(“2012- 04-01T00:00:00”)}}) > {“_id”: ObjectId(41234351451345), “title” : “CodeCraft Meeting”, “description” : “Description”, “start_datetime” : ISODate(“2012-04-03T17:30:00”), “category” : “social”} {“_id”: ObjectId(41226542345234), “title” : “CodeCraft Meeting 2”, “description” : “Description”, “start_datetime” : ISODate(“2012-05-03T17:30:00”), “category” : “social”, “participants” : 50}
  • 12. Updates • Replacing the entire document > db.events.update({“_id”: ObjectId(41234351451345)}, {“title” : “New Title”, “description” : “Description”, “start_date” : ISODate(“2012-04-03T17:30:00”), “category” : “social”, “comments”: [ {“author”: <user_id>, “comment” :“My First Comment”}, {“author”: <user_id>, “comment”: “My Second Comment” }) • Atomic updates > db.events.update({“_id”:ObjectId(41234351451345)}, {$set : {“title”: {“New Title”}}} )
  • 13. Updates (2) • Pushing Elements to Arrays > db.events.update({“_id”:ObjectId(41234351451345)}, {$push : {“comments”: {“author”: <user_id>, “comment”: “My Third Comment”}}}) > {“title” : “Title”, “description” : “Description”, “start_date” : ISODate(“2012-04-03T17:30:00”), “category” : “social”, “comments”: [ {“author”: <user_id>, “comment” :“My First Comment”}, {“author”: <user_id>, “comment”: “My Second Comment”}, {“author”: <user_id>, “comment”: “My Third Comment”}] })
  • 14. Geospatial queries • MongoDB has build-in support for geospacial queries > db.events.insert({ “title” : “Title”, “description” : “Description”, “start_datetime” : ISODate(“2012-04-03T17:30:00”), “category” : “social”, “location” : [30, 30] }) > db.events.ensureIndex({“location” : “2d”}) > db.events.find({“location”: {$near: [28,28], $maxDistance: 5}})
  • 15. Files (GridFS) • In MySQL it’s a bad practice to save large binary files into the database • In MongoDB it’s a bad practice NOT TO save large files into the database. • MongoDB splits saved files into chunks, which allows querying of only necessary parts of the binary files • Example(pymongo library) >>> fs = gridfs.GridFs(db_name) >>> filename = fs.put(“Example file data”) >>> file_data = fs.get(filename).read()
  • 16. Map/Reduce db.events.mapReduce(map_func, reduce_func, {out: “out_collection”}) • map_func and reduce_func are written in JavaScript • Output of reduce_func is stored in output collection
  • 17. Language Drivers • Different language drivers for MongoDB provide different levels of abstraction – PyMongo (similar to mongo shell) vs MongoEngine (ORM-like) class Event(mongoengine.Document): title = StringField() description = StringField() start_date = DateTimeField(default=datetime.now) category = StringField() comments = ListField(EmbeddedDocumentField(Comment)) #querying event = Events.objects(title = “Title”) #adding comments event.update(push__comments = comment)