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.
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 ...