I will have to sort the data based on date and pagination. This is the query I use: response.data =Waiting for distributorDoc.find().sort({"TimeStamp":-1,}); This is pagination: Pagination: { Total: 0, Number of pages: 0, Current page: page number, Per page: reqData.perPage || Count per page }
response.data =Waiting for distributorDoc.find().sort({"TimeStamp":-1,"perpage"==100});
You can try using MongoDB's
limit
andskip
methods.The limit() function in MongoDB is used to specify the maximum number of results to be returned.
If you want to get a specific number of results after certain documents, you can use the skip() function.
Sample Node JS code for pagination:
Read more here
limit()
skip()
Check out this link for other alternatives
Hope this is what you are looking for.