SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
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?

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

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

Semelhante 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
 

Semelhante 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

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Último (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 

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)