Finding Documents by Using Mongoose

Finding documents by using the mongoose module is very similar to using the MongoDB Node.js native driver and yet very different in some ways. The concepts of logic operators, limit, skip, and distinct are all the same. However, there are two big differences. The first major difference is that when using Mongoose, the statements used to build the request can be piped together and reused because of the Query object, discussed earlier in this chapter. This allows Mongoose code to be much more dynamic and flexible when defining what documents to return and how to return them.

For example, these three queries are identical, just built in different ways:

var query1 = model.find({name:'test'}, ...

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.