File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -25,11 +25,15 @@ db.sales.insertMany([
25
25
// Run a find command to view items sold on April 4th, 2014.
26
26
db.sales.find({ date: { $gte: new Date('2014-04-04'), $lt: new Date('2014-04-05') } });
27
27
28
- // Run an aggregation to view total sales for each product in 2014.
28
+ // Build an aggregation to view total sales for each product in 2014.
29
29
const aggregation = [
30
30
{ $match: { date: { $gte: new Date('2014-01-01'), $lt: new Date('2015-01-01') } } },
31
31
{ $group: { _id: '$item', totalSaleAmount: { $sum: { $multiply: [ '$price', '$quantity' ] } } } }
32
32
];
33
+
34
+ // Run the aggregation and open a cursor to the results.
35
+ // Use toArray() to exhaust the cursor to return the whole result set.
36
+ // You can use hasNext()/next() to iterate through the cursor page by page.
33
37
db.sales.aggregate(aggregation);
34
38
` ;
35
39
You can’t perform that action at this time.
0 commit comments