O'Reilly logo

Node.js, MongoDB, and AngularJS Web Development by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required