Node.js API: Add CRUD Operations With Pagination, Filtering, Grouping, and Sorting Capabilities.
Add CRUD and Aggregation operations including Pagination, Sorting, Filtering and Partial Text Search to your Node.js REST API.
Published in
8 min readJan 14, 2020
In my previous Node.js tutorial, I outlined the steps required to build a Node.js Authentication API with Email Verification, Image Upload and Password Reset Using JWT, Passport.js, and Sendgrid.
This tutorial will be a continuation of that tutorial, CRUD operations will be added for an ‘Event’ resource, users’ will have the ability to create, read, update and delete events.
The API will include:
- Pagination: users can dictate how many results they want (limit) and can also page through the result by passing the ‘page’ number in the URL query parameters.
- Filtering: users can also specify an event date to filter by
- Partial Text Search: users can search by event name, regex is utilized to perform a search against the name column in the database.
- Grouping: by default, all events are grouped by date, users can set this to false
- Sorting: results can be sorted in ascending order(asc), which is the default or in descending order (desc)
Mongoose Aggregate constructor is used along with mongoose-aggregate-paginate-v2, a cursor based custom pagination…