SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
DeNormalised London:
              Aggregation Framework Overview
                                 Chris Harris
                         Email : charris@10gen.com
                            Twitter : cj_harris5



Wednesday, 21 March 12
Terminology

          RDBMS              MongoDB
          Table              Collection
          Row(s)             JSON Document
          Index              Index
          Join               Embedding & Linking
          Partition          Shard
          Partition Key      Shard Key


Wednesday, 21 March 12
Here is a “simple” SQL Model
     mysql> select * from book;
     +----+----------------------------------------------------------+
     | id | title                            |
     +----+----------------------------------------------------------+
     | 1 | The Demon-Haunted World: Science as a Candle in the Dark |
     | 2 | Cosmos                               |
     | 3 | Programming in Scala                     |
     +----+----------------------------------------------------------+
     3 rows in set (0.00 sec)

     mysql> select * from bookauthor;
     +---------+-----------+
     | book_id | author_id |
     +---------+-----------+
     |    1|       1|
     |    2|       1|
     |    3|       2|
     |    3|       3|
     |    3|       4|
     +---------+-----------+
     5 rows in set (0.00 sec)

     mysql> select * from author;
     +----+-----------+------------+-------------+-------------+---------------+
     | id | last_name | rst_name | middle_name | nationality | year_of_birth |
     +----+-----------+------------+-------------+-------------+---------------+
     | 1 | Sagan    | Carl     | Edward    | NULL    | 1934         |
     | 2 | Odersky | Martin       | NULL     | DE     | 1958         |
     | 3 | Spoon    | Lex      | NULL     | NULL    | NULL         |
     | 4 | Venners | Bill      | NULL    | NULL     | NULL        |
     +----+-----------+------------+-------------+-------------+---------------+
     4 rows in set (0.00 sec)




Wednesday, 21 March 12
The Same Data in MongoDB

             {
         "_id" : ObjectId("4dfa6baa9c65dae09a4bbda5"),
         "title" : "Programming in Scala",
         "author" : [
            {
               "rst_name" : "Martin",
               "last_name" : "Odersky",
               "nationality" : "DE",
               "year_of_birth" : 1958
            },
            {
               "rst_name" : "Lex",
               "last_name" : "Spoon"
            },
            {
               "rst_name" : "Bill",
               "last_name" : "Venners"
            }
         ]
     }




Wednesday, 21 March 12
What problem are we solving?
     • Map/Reduce can be used for aggregation…
          • Currently being used for totaling, averaging, etc
     • Map/Reduce is a big hammer
          • Simpler tasks should be easier
            • Shouldn’t need to write JavaScript
            • Avoid the overhead of JavaScript engine
     • We’re seeing requests for help in handling
          complex documents
          • Select only matching subdocuments or arrays




Wednesday, 21 March 12
How will we solve the problem?
     • New aggregation framework
          • Declarative framework (no JavaScript)
          • Describe a chain of operations to apply
          • Expression evaluation
            • Return computed values
          • Framework: new operations added easily
          • C++ implementation




Wednesday, 21 March 12
Aggregation - Pipelines
     • Aggregation requests specify a pipeline
     • A pipeline is a series of operations
     • Members of a collection are passed
          through a pipeline to produce a result
          • ps -ef | grep -i mongod




Wednesday, 21 March 12
Example - twitter
         {
             "_id" : ObjectId("4f47b268fb1c80e141e9888c"),
             "user" : {
               "friends_count" : 73,
               "location" : "Brazil",
               "screen_name" : "Bia_cunha1",
               "name" : "Beatriz Helena Cunha",
               "followers_count" : 102,
             }
         }


     • Find the # of followers and # friends by location


Wednesday, 21 March 12
Example - twitter
       db.tweets.aggregate(
         {$match:
           {"user.friends_count": { $gt: 0 },
            "user.followers_count": { $gt: 0 }
           }
         },
         {$project:
           { location: "$user.location",
             friends: "$user.friends_count",
             followers: "$user.followers_count"
           }
         },
         {$group:
           {_id:     "$location",
            friends: {$sum: "$friends"},
            followers: {$sum: "$followers"}
           }
         }
       );




Wednesday, 21 March 12
Example - twitter
       db.tweets.aggregate(
         {$match:
           {"user.friends_count": { $gt: 0 },     Predicate
            "user.followers_count": { $gt: 0 }
           }
         },
         {$project:
           { location: "$user.location",
             friends: "$user.friends_count",
             followers: "$user.followers_count"
           }
         },
         {$group:
           {_id:     "$location",
            friends: {$sum: "$friends"},
            followers: {$sum: "$followers"}
           }
         }
       );




Wednesday, 21 March 12
Example - twitter
       db.tweets.aggregate(
         {$match:
           {"user.friends_count": { $gt: 0 },      Predicate
            "user.followers_count": { $gt: 0 }
           }
         },
         {$project:
           { location: "$user.location",
                                                   Parts of the
             friends: "$user.friends_count",      document you
             followers: "$user.followers_count"   want to project
           }
         },
         {$group:
           {_id:     "$location",
            friends: {$sum: "$friends"},
            followers: {$sum: "$followers"}
           }
         }
       );




Wednesday, 21 March 12
Example - twitter
       db.tweets.aggregate(
         {$match:
           {"user.friends_count": { $gt: 0 },      Predicate
            "user.followers_count": { $gt: 0 }
           }
         },
         {$project:
           { location: "$user.location",
                                                   Parts of the
             friends: "$user.friends_count",      document you
             followers: "$user.followers_count"   want to project
           }
         },
         {$group:
           {_id:     "$location",                 Function to
            friends: {$sum: "$friends"},          apply to the
            followers: {$sum: "$followers"}
           }                                       result set
         }
       );




Wednesday, 21 March 12
Example - twitter
       {
       
      "result" : [
       
      
       {
       
      
       
      "_id" : "Far Far Away",
       
      
       
      "friends" : 344,
       
      
       
      "followers" : 789
       
      
       },
       ...
       
      ],
       
      "ok" : 1
       }




Wednesday, 21 March 12
Demo
                  Demo les are at https://gist.github.com/
                                  2036709




Wednesday, 21 March 12
Projections
     • $project can reshape results
          • Include or exclude fields
          • Computed fields
            • Arithmetic expressions
            • Pull fields from nested documents to the top
            • Push fields from the top down into new virtual
              documents




Wednesday, 21 March 12
Unwinding
     • $unwind can “stream” arrays
          • Array values are doled out one at time in the
            context of their surrounding documents
          • Makes it possible to filter out elements before
            returning




Wednesday, 21 March 12
Grouping
     • $group aggregation expressions
          • Define a grouping key as the _id of the result
          • Total grouped column values: $sum
          • Average grouped column values: $avg
          • Collect grouped column values in an array or
            set: $push, $addToSet
          • Other functions
              • $min, $max, $first, $last




Wednesday, 21 March 12
Sorting
     • $sort can sort documents
          • Sort specifications are the same as today,
              e.g., $sort:{ key1: 1, key2: -1, …}




Wednesday, 21 March 12
Computed Expressions
     • Available in $project operations
     • Prefix expression language
          • $add:[“$field1”, “$field2”]
          • $ifNull:[“$field1”, “$field2”]
          • Nesting: $add:[“$field1”, $ifNull:[“$field2”,
            “$field3”]]
          • Other functions….
              • $divide, $mod, $multiply




Wednesday, 21 March 12
Computed Expressions
     • String functions
          • $toUpper, $toLower, $substr
     • Date field extraction
          • $year, $month, $day, $hour...
     • Date arithmetic
     • $ifNull
     • Ternary conditional
          • Return one of two values based on a
              predicate




Wednesday, 21 March 12
download at mongodb.org

                            We’re Hiring !
                                  Chris Harris
                          Email : charris@10gen.com
                             Twitter : cj_harris5

                         conferences, appearances
                         http://www.10gen.com/events
                               and meetups
       http://www.meetup.com/London-MongoDB-User-Group




Wednesday, 21 March 12

Weitere ähnliche Inhalte

Was ist angesagt?

MongoD Essentials
MongoD EssentialsMongoD Essentials
MongoD Essentialszahid-mian
 
First app online conf
First app   online confFirst app   online conf
First app online confMongoDB
 
Storing tree structures with MongoDB
Storing tree structures with MongoDBStoring tree structures with MongoDB
Storing tree structures with MongoDBVyacheslav
 
Jan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World SettingJan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World SettingGeorge Ang
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapHoward Lewis Ship
 
Meetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4jMeetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4jNeo4j
 
MongoDB .local Bengaluru 2019: Aggregation Pipeline Power++: How MongoDB 4.2 ...
MongoDB .local Bengaluru 2019: Aggregation Pipeline Power++: How MongoDB 4.2 ...MongoDB .local Bengaluru 2019: Aggregation Pipeline Power++: How MongoDB 4.2 ...
MongoDB .local Bengaluru 2019: Aggregation Pipeline Power++: How MongoDB 4.2 ...MongoDB
 
Schema design
Schema designSchema design
Schema designchristkv
 
Aggregation Framework
Aggregation FrameworkAggregation Framework
Aggregation FrameworkMongoDB
 
Webinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation FrameworkWebinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation FrameworkMongoDB
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation FrameworkTyler Brock
 
MongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
MongoDB Europe 2016 - Advanced MongoDB Aggregation PipelinesMongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
MongoDB Europe 2016 - Advanced MongoDB Aggregation PipelinesMongoDB
 
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB
 
Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2MongoDB
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling rogerbodamer
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know Norberto Leite
 
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.GeeksLab Odessa
 
Doing More with MongoDB Aggregation
Doing More with MongoDB AggregationDoing More with MongoDB Aggregation
Doing More with MongoDB AggregationMongoDB
 

Was ist angesagt? (20)

MongoD Essentials
MongoD EssentialsMongoD Essentials
MongoD Essentials
 
First app online conf
First app   online confFirst app   online conf
First app online conf
 
Storing tree structures with MongoDB
Storing tree structures with MongoDBStoring tree structures with MongoDB
Storing tree structures with MongoDB
 
Jan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World SettingJan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World Setting
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter Bootstrap
 
Meetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4jMeetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4j
 
MongoDB .local Bengaluru 2019: Aggregation Pipeline Power++: How MongoDB 4.2 ...
MongoDB .local Bengaluru 2019: Aggregation Pipeline Power++: How MongoDB 4.2 ...MongoDB .local Bengaluru 2019: Aggregation Pipeline Power++: How MongoDB 4.2 ...
MongoDB .local Bengaluru 2019: Aggregation Pipeline Power++: How MongoDB 4.2 ...
 
Schema design
Schema designSchema design
Schema design
 
Talk MongoDB - Amil
Talk MongoDB - AmilTalk MongoDB - Amil
Talk MongoDB - Amil
 
Aggregation Framework
Aggregation FrameworkAggregation Framework
Aggregation Framework
 
Webinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation FrameworkWebinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation Framework
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
MongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
MongoDB Europe 2016 - Advanced MongoDB Aggregation PipelinesMongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
MongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
 
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
 
Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
 
Doing More with MongoDB Aggregation
Doing More with MongoDB AggregationDoing More with MongoDB Aggregation
Doing More with MongoDB Aggregation
 
Mongo db presentation
Mongo db presentationMongo db presentation
Mongo db presentation
 

Andere mochten auch

Blogging4Good @ BlogCamp Mumbai 2010 - Ads4Good.org
Blogging4Good @ BlogCamp Mumbai 2010 - Ads4Good.orgBlogging4Good @ BlogCamp Mumbai 2010 - Ads4Good.org
Blogging4Good @ BlogCamp Mumbai 2010 - Ads4Good.org★ Akshay Surve
 
MisiĂłn Comercial a MĂŠxico
MisiĂłn Comercial  a MĂŠxicoMisiĂłn Comercial  a MĂŠxico
MisiĂłn Comercial a MĂŠxicopymesaldia
 
E223539
E223539E223539
E223539irjes
 
Proyecto tabletas
Proyecto tabletasProyecto tabletas
Proyecto tabletasFabian Roldan
 
Os Harris
Os HarrisOs Harris
Os Harrisoscon2007
 
Putting Medical Officer of Health Reports on the map - Natalie Pollecutt, Wel...
Putting Medical Officer of Health Reports on the map - Natalie Pollecutt, Wel...Putting Medical Officer of Health Reports on the map - Natalie Pollecutt, Wel...
Putting Medical Officer of Health Reports on the map - Natalie Pollecutt, Wel...JISC GECO
 
seguridad
seguridadseguridad
seguridadphunziker
 

Andere mochten auch (7)

Blogging4Good @ BlogCamp Mumbai 2010 - Ads4Good.org
Blogging4Good @ BlogCamp Mumbai 2010 - Ads4Good.orgBlogging4Good @ BlogCamp Mumbai 2010 - Ads4Good.org
Blogging4Good @ BlogCamp Mumbai 2010 - Ads4Good.org
 
MisiĂłn Comercial a MĂŠxico
MisiĂłn Comercial  a MĂŠxicoMisiĂłn Comercial  a MĂŠxico
MisiĂłn Comercial a MĂŠxico
 
E223539
E223539E223539
E223539
 
Proyecto tabletas
Proyecto tabletasProyecto tabletas
Proyecto tabletas
 
Os Harris
Os HarrisOs Harris
Os Harris
 
Putting Medical Officer of Health Reports on the map - Natalie Pollecutt, Wel...
Putting Medical Officer of Health Reports on the map - Natalie Pollecutt, Wel...Putting Medical Officer of Health Reports on the map - Natalie Pollecutt, Wel...
Putting Medical Officer of Health Reports on the map - Natalie Pollecutt, Wel...
 
seguridad
seguridadseguridad
seguridad
 

Ähnlich wie De normalised london aggregation framework overview

MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation FrameworkCaserta
 
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & AggregationWebinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & AggregationMongoDB
 
1403 app dev series - session 5 - analytics
1403   app dev series - session 5 - analytics1403   app dev series - session 5 - analytics
1403 app dev series - session 5 - analyticsMongoDB
 
MongoDB 3.2 - Analytics
MongoDB 3.2  - AnalyticsMongoDB 3.2  - Analytics
MongoDB 3.2 - AnalyticsMassimo Brignoli
 
Joins and Other MongoDB 3.2 Aggregation Enhancements
Joins and Other MongoDB 3.2 Aggregation EnhancementsJoins and Other MongoDB 3.2 Aggregation Enhancements
Joins and Other MongoDB 3.2 Aggregation EnhancementsAndrew Morgan
 
2012 mongo db_bangalore_roadmap_new
2012 mongo db_bangalore_roadmap_new2012 mongo db_bangalore_roadmap_new
2012 mongo db_bangalore_roadmap_newMongoDB
 
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
 
Building a Cross Channel Content Delivery Platform with MongoDB
Building a Cross Channel Content Delivery Platform with MongoDBBuilding a Cross Channel Content Delivery Platform with MongoDB
Building a Cross Channel Content Delivery Platform with MongoDBMongoDB
 
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDBMongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDBMongoDB
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Javaantoinegirbal
 
How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6Maxime Beugnet
 
CouchDB on Rails
CouchDB on RailsCouchDB on Rails
CouchDB on RailsJonathan Weiss
 
CouchDB on Rails - RailsWayCon 2010
CouchDB on Rails - RailsWayCon 2010CouchDB on Rails - RailsWayCon 2010
CouchDB on Rails - RailsWayCon 2010Jonathan Weiss
 
CouchDB on Rails - FrozenRails 2010
CouchDB on Rails - FrozenRails 2010CouchDB on Rails - FrozenRails 2010
CouchDB on Rails - FrozenRails 2010Jonathan Weiss
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsMongoDB
 
Powerful Analysis with the Aggregation Pipeline
Powerful Analysis with the Aggregation PipelinePowerful Analysis with the Aggregation Pipeline
Powerful Analysis with the Aggregation PipelineMongoDB
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDBMongoDB
 

Ähnlich wie De normalised london aggregation framework overview (20)

MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & AggregationWebinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
 
1403 app dev series - session 5 - analytics
1403   app dev series - session 5 - analytics1403   app dev series - session 5 - analytics
1403 app dev series - session 5 - analytics
 
MongoDB 3.2 - Analytics
MongoDB 3.2  - AnalyticsMongoDB 3.2  - Analytics
MongoDB 3.2 - Analytics
 
Joins and Other MongoDB 3.2 Aggregation Enhancements
Joins and Other MongoDB 3.2 Aggregation EnhancementsJoins and Other MongoDB 3.2 Aggregation Enhancements
Joins and Other MongoDB 3.2 Aggregation Enhancements
 
2012 mongo db_bangalore_roadmap_new
2012 mongo db_bangalore_roadmap_new2012 mongo db_bangalore_roadmap_new
2012 mongo db_bangalore_roadmap_new
 
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
 
Building a Cross Channel Content Delivery Platform with MongoDB
Building a Cross Channel Content Delivery Platform with MongoDBBuilding a Cross Channel Content Delivery Platform with MongoDB
Building a Cross Channel Content Delivery Platform with MongoDB
 
MongoDB Meetup
MongoDB MeetupMongoDB Meetup
MongoDB Meetup
 
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDBMongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
 
Mongo DB 102
Mongo DB 102Mongo DB 102
Mongo DB 102
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Java
 
MongoDB
MongoDB MongoDB
MongoDB
 
How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6
 
CouchDB on Rails
CouchDB on RailsCouchDB on Rails
CouchDB on Rails
 
CouchDB on Rails - RailsWayCon 2010
CouchDB on Rails - RailsWayCon 2010CouchDB on Rails - RailsWayCon 2010
CouchDB on Rails - RailsWayCon 2010
 
CouchDB on Rails - FrozenRails 2010
CouchDB on Rails - FrozenRails 2010CouchDB on Rails - FrozenRails 2010
CouchDB on Rails - FrozenRails 2010
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
 
Powerful Analysis with the Aggregation Pipeline
Powerful Analysis with the Aggregation PipelinePowerful Analysis with the Aggregation Pipeline
Powerful Analysis with the Aggregation Pipeline
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 

KĂźrzlich hochgeladen

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 

KĂźrzlich hochgeladen (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 

De normalised london aggregation framework overview

  • 1. DeNormalised London: Aggregation Framework Overview Chris Harris Email : charris@10gen.com Twitter : cj_harris5 Wednesday, 21 March 12
  • 2. Terminology RDBMS MongoDB Table Collection Row(s) JSON Document Index Index Join Embedding & Linking Partition Shard Partition Key Shard Key Wednesday, 21 March 12
  • 3. Here is a “simple” SQL Model mysql> select * from book; +----+----------------------------------------------------------+ | id | title | +----+----------------------------------------------------------+ | 1 | The Demon-Haunted World: Science as a Candle in the Dark | | 2 | Cosmos | | 3 | Programming in Scala | +----+----------------------------------------------------------+ 3 rows in set (0.00 sec) mysql> select * from bookauthor; +---------+-----------+ | book_id | author_id | +---------+-----------+ | 1| 1| | 2| 1| | 3| 2| | 3| 3| | 3| 4| +---------+-----------+ 5 rows in set (0.00 sec) mysql> select * from author; +----+-----------+------------+-------------+-------------+---------------+ | id | last_name | rst_name | middle_name | nationality | year_of_birth | +----+-----------+------------+-------------+-------------+---------------+ | 1 | Sagan | Carl | Edward | NULL | 1934 | | 2 | Odersky | Martin | NULL | DE | 1958 | | 3 | Spoon | Lex | NULL | NULL | NULL | | 4 | Venners | Bill | NULL | NULL | NULL | +----+-----------+------------+-------------+-------------+---------------+ 4 rows in set (0.00 sec) Wednesday, 21 March 12
  • 4. The Same Data in MongoDB { "_id" : ObjectId("4dfa6baa9c65dae09a4bbda5"), "title" : "Programming in Scala", "author" : [ { "rst_name" : "Martin", "last_name" : "Odersky", "nationality" : "DE", "year_of_birth" : 1958 }, { "rst_name" : "Lex", "last_name" : "Spoon" }, { "rst_name" : "Bill", "last_name" : "Venners" } ] } Wednesday, 21 March 12
  • 5. What problem are we solving? • Map/Reduce can be used for aggregation… • Currently being used for totaling, averaging, etc • Map/Reduce is a big hammer • Simpler tasks should be easier • Shouldn’t need to write JavaScript • Avoid the overhead of JavaScript engine • We’re seeing requests for help in handling complex documents • Select only matching subdocuments or arrays Wednesday, 21 March 12
  • 6. How will we solve the problem? • New aggregation framework • Declarative framework (no JavaScript) • Describe a chain of operations to apply • Expression evaluation • Return computed values • Framework: new operations added easily • C++ implementation Wednesday, 21 March 12
  • 7. Aggregation - Pipelines • Aggregation requests specify a pipeline • A pipeline is a series of operations • Members of a collection are passed through a pipeline to produce a result • ps -ef | grep -i mongod Wednesday, 21 March 12
  • 8. Example - twitter { "_id" : ObjectId("4f47b268fb1c80e141e9888c"), "user" : { "friends_count" : 73, "location" : "Brazil", "screen_name" : "Bia_cunha1", "name" : "Beatriz Helena Cunha", "followers_count" : 102, } } • Find the # of followers and # friends by location Wednesday, 21 March 12
  • 9. Example - twitter db.tweets.aggregate( {$match: {"user.friends_count": { $gt: 0 }, "user.followers_count": { $gt: 0 } } }, {$project: { location: "$user.location", friends: "$user.friends_count", followers: "$user.followers_count" } }, {$group: {_id: "$location", friends: {$sum: "$friends"}, followers: {$sum: "$followers"} } } ); Wednesday, 21 March 12
  • 10. Example - twitter db.tweets.aggregate( {$match: {"user.friends_count": { $gt: 0 }, Predicate "user.followers_count": { $gt: 0 } } }, {$project: { location: "$user.location", friends: "$user.friends_count", followers: "$user.followers_count" } }, {$group: {_id: "$location", friends: {$sum: "$friends"}, followers: {$sum: "$followers"} } } ); Wednesday, 21 March 12
  • 11. Example - twitter db.tweets.aggregate( {$match: {"user.friends_count": { $gt: 0 }, Predicate "user.followers_count": { $gt: 0 } } }, {$project: { location: "$user.location", Parts of the friends: "$user.friends_count", document you followers: "$user.followers_count" want to project } }, {$group: {_id: "$location", friends: {$sum: "$friends"}, followers: {$sum: "$followers"} } } ); Wednesday, 21 March 12
  • 12. Example - twitter db.tweets.aggregate( {$match: {"user.friends_count": { $gt: 0 }, Predicate "user.followers_count": { $gt: 0 } } }, {$project: { location: "$user.location", Parts of the friends: "$user.friends_count", document you followers: "$user.followers_count" want to project } }, {$group: {_id: "$location", Function to friends: {$sum: "$friends"}, apply to the followers: {$sum: "$followers"} } result set } ); Wednesday, 21 March 12
  • 13. Example - twitter { "result" : [ { "_id" : "Far Far Away", "friends" : 344, "followers" : 789 }, ... ], "ok" : 1 } Wednesday, 21 March 12
  • 14. Demo Demo les are at https://gist.github.com/ 2036709 Wednesday, 21 March 12
  • 15. Projections • $project can reshape results • Include or exclude elds • Computed elds • Arithmetic expressions • Pull elds from nested documents to the top • Push elds from the top down into new virtual documents Wednesday, 21 March 12
  • 16. Unwinding • $unwind can “stream” arrays • Array values are doled out one at time in the context of their surrounding documents • Makes it possible to lter out elements before returning Wednesday, 21 March 12
  • 17. Grouping • $group aggregation expressions • Dene a grouping key as the _id of the result • Total grouped column values: $sum • Average grouped column values: $avg • Collect grouped column values in an array or set: $push, $addToSet • Other functions • $min, $max, $rst, $last Wednesday, 21 March 12
  • 18. Sorting • $sort can sort documents • Sort specications are the same as today, e.g., $sort:{ key1: 1, key2: -1, …} Wednesday, 21 March 12
  • 19. Computed Expressions • Available in $project operations • Prex expression language • $add:[“$eld1”, “$eld2”] • $ifNull:[“$eld1”, “$eld2”] • Nesting: $add:[“$eld1”, $ifNull:[“$eld2”, “$eld3”]] • Other functions…. • $divide, $mod, $multiply Wednesday, 21 March 12
  • 20. Computed Expressions • String functions • $toUpper, $toLower, $substr • Date eld extraction • $year, $month, $day, $hour... • Date arithmetic • $ifNull • Ternary conditional • Return one of two values based on a predicate Wednesday, 21 March 12
  • 21. download at mongodb.org We’re Hiring ! Chris Harris Email : charris@10gen.com Twitter : cj_harris5 conferences, appearances http://www.10gen.com/events and meetups http://www.meetup.com/London-MongoDB-User-Group Wednesday, 21 March 12