Instead of SQL to query data from the database, Mongoose relies on using the JavaScript method chaining to build logical queries, which will be sent over to MongoDB once executed. The model API already exposed us to some rudimentary queries through methods like find and where, but we can expand upon those greatly with Mongoose's query API methods.
Querying for data using Mongoose query selectors
How to do it...
Let's follow these steps to add query parameters to our Express /api/post REST endpoint to support pagination. We will also implement some advanced filtering queries, including date range filtering to our API:
- First, we'll extend the list method of our /middleware/rest.js middleware to parse query parameters...