Aggregating Documents by Using Mongoose
The Model
object provides an aggregate()
method that allows you to implement the MongoDB aggregation pipeline discussed in Chapter 15. If you haven’t already read the aggregation information in Chapter 15, you should read it before you read this section. It works here very similarly to the way it works in the MongoDB Node.js native driver. In fact, you can use exactly the same syntax if you want to. You also have the option of using the Mongoose Aggregate
object to build and then execute the aggregation pipeline.
The Aggregate
object works very similarly to the Query
object in that if you pass in a callback function, aggregate()
is executed immediately; if not, an Aggregate
object is returned, and you ...
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.