I will have to use MongoDB to sort the data by page
P粉043566314
P粉043566314 2023-09-11 10:37:11
0
1
433

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});

P粉043566314
P粉043566314

reply all(1)
P粉338969567

You can try using MongoDB's limit and skip 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:

    function fetchDocs(pageNumber, nPerPage) {
        console.log('Page: ' + pageNumber);
        distributorDoc.find()
          .sort({'TimeStamp': -1})
          .skip(pageNumber > 0 ? ((pageNumber - 1) * nPerPage) : 0)
          .limit(nPerPage)
          .forEach(doc => {
              console.log(doc);
          });
     }

Read more here

limit()

skip()

Check out this link for other alternatives

Hope this is what you are looking for.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!