7. Data Aggregation
Activity 7.01: Putting Aggregations into Practice
Solution:
Perform the following steps to complete the activity:
- First, create the scaffold code:
// Chapter_7_Activity.js var chapter7Activity = function() { var pipeline = []; db.movies.aggregate(pipeline).forEach(printjson); } Chapter7Activity()
- Add the first match for documents older than 2001:
var pipeline = [ {$match: { released: {$lte: new ISODate("2001-01-01T00:00:00Z")} }} ];
- Add a second match condition for movies with at least one award win:
{$match: { released: {$lte: new ISODate("2001-01-01T00:00:00Z")}, "awards.wins": {$gte: 1}, }}
- Add a
sort
condition...