Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

pagination in mongoose express node.js

//Pagination
    //page=2,limit=10
    let page = req.query.page * 1 || 1;
    let limit = req.query.limit * 1 || 100;
    let skip = (page - 1) * limit;
    query = query.skip(skip).limit(limit);
    if (req.query.page) {
      const numTours = await Tour.countDocuments();
      if (skip >= numTours) throw new Error('This page does not exists');
    }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pagination #mongoose #express
ADD COMMENT
Topic
Name
9+1 =