Aggregation Examples
Listing 15.9 shows how to implement aggregation against the words collection. It includes three examples.
The first example, in lines 10–20, implements a $match
to get words beginning in vowels, then a $group
to calculate the largest and smallest sizes. It then sorts the results using $sort
, as shown in Figure 15.9.
The second example, in lines 21–27, uses $match
to limit the words to four letters. Then $limit
is used to process only five documents in the $project
operator.
The third example, in lines 28–34, uses $group
to get the average size ...
Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.