I will have to sort data by data and acccording to the pagination.
This is the query which I used
response.data = await distributorDoc.find().sort({"TimeStamp":-1,});
It is the pagination
pagination: {
totalCount: 0,
pageCount: 0,
currentPage: page,
perPage: reqData.perPage || perPageCount
}
response.data = await distributorDoc.find().sort({"TimeStamp":-1,"perpage"==100});
2
Answers
You could try with
limit
andskip
methods from MongoDB.The limit() function in MongoDB is used to specify the maximum number of results to be returned
If you want to get certain number of results after some documents, you could use skip() function.
Sample Node JS code for pagination:
Read more about them here
limit()
skip()
Checkout this link for other alternatives
Hope this is what you’re looking for.
Here’s an example of how you can do it assuming you have the following variables:
page: The current page number.
perPage: The number of items you want to show per page.
distributorDoc: The Mongoose model for your distributor document.