Implement pagination, filtering, and sorting for a resource (Students) using Node.js, Express, and MongoDB.
- Setup Node.js project and install dependencies.
- Create
.env
for PORT and MongoDB URI. - Create Student model with fields: name, age, grade, city.
- Implement Express routes:
- POST /students → Add a student
- GET /students → List students with:
- Pagination: page & limit
- Filtering: grade & city
- Sorting: sortBy & order
- Test using Postman:
- Add multiple students
- Retrieve students using queries like:
/students?page=1&limit=2
/students?grade=A&city=New York
/students?sortBy=age&order=desc
App Screenshot:
- Default page = 1, limit = 5
- Sorting order: asc (ascending) / desc (descending)
- Filtering fields are optional