Skip to content

Commit bd2227c

Browse files
authored
fix: update playground template to add a comment for .toArray to aggregation run (#274)
1 parent 6ca0514 commit bd2227c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/templates/playgroundTemplate.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ db.sales.insertMany([
2525
// Run a find command to view items sold on April 4th, 2014.
2626
db.sales.find({ date: { $gte: new Date('2014-04-04'), $lt: new Date('2014-04-05') } });
2727
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.
2929
const aggregation = [
3030
{ $match: { date: { $gte: new Date('2014-01-01'), $lt: new Date('2015-01-01') } } },
3131
{ $group: { _id: '$item', totalSaleAmount: { $sum: { $multiply: [ '$price', '$quantity' ] } } } }
3232
];
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.
3337
db.sales.aggregate(aggregation);
3438
`;
3539

0 commit comments

Comments
 (0)