Webinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & Aggregation
1. Solutions Architect, MongoDB
Marc Schwering
#MongoDBBasics @MongoDB @m4rcsch
Applikationsentwicklung mit MongoDB
Reporting & Aggregation
2. 2
• Recap from last session
• Reporting / Analytics options
• Map Reduce
• Aggregation Framework introduction
– Aggregation explain
• mycms application reports
• Geospatial with Aggregation Framework
• Text Search with Aggregation Framework
Agenda
3. 3
• Virtual Genius Bar
– Use the chat to post
questions
– EMEA Solution
Architecture / Support
team are on hand
– Make use of them
during the sessions!!!
Q & A
8. 8
• Query Language
– Leverage pre aggregated documents
• Aggregation Framework
– Calculate new values from the data that we have
– For instance : Average views, comments count
• MapReduce
– Internal Javascript based implementation
– External Hadoop, using the MongoDB connector
• A combination of the above
Access data for reporting, options
18. 18
• What reports and analytics do we need in our
application?
– Popular Tags
– Popular Articles
– Popular Locations – integration with Geo Spatial
– Average views per hour or day
Application Reports
19. 19
• Unwind each ‘tags’ array
• Group and count each one, then Sort
• Output to new collection
– Query from new collection so don’t need to compute for
every request.
Popular Tags
db.articles.aggregate([
{ $unwind : "$tags" },
{ $group : { _id : "$tags" , number : { $sum : 1 } } },
{ $sort : { number : -1 } },
{ $out : "tags"}
])
20. 20
• Top 5 articles by average daily views
– Use the $avg operator
– Use use $match to constrain data range
• Utilise with $gt and $lt operators
Popular Articles
db.interactions.aggregate([
{
{$match : { date :
{ $gt : ISODate("2014-02-20T00:00:00.000Z")}}},
{$group : {_id: "$article_id", a : { $avg : "$daily.view"}}},
{$sort : { a : -1}},
{$limit : 5}
]);
21. 21
• Use Explain plan to ensure the efficient use of the
index when querying.
Aggregation Framework Explain
db.interactions.aggregate([
{$group : {_id: "$article_id", a : { $avg : "$daily.view"}}},
{$sort : { a : -1}},
{$limit : 5}
],
{explain : true}
);
27. 27
• Aggregating Data…
– Map Reduce
– Hadoop
– Pre-Aggregated Reports
– Aggregation Framework
• Tune with Explain plan
• Compute on the fly or Compute and store
• Geospatial
• Text Search
Summary
28. 28
– MongoDB World Recap!
– Preview into the operation Series.
Next Session – 9th July