paginationnodeApi

 


//pagination:---
// ..........
//the rule of api is the root has to be same..
router.get('/Myapp'async (reqres=> {
    
    try {
        console.log("gud morning");
       let page=Number(req.query.page)||1;
       console.log(page);
       let limit=Number(req.query.limit)||2;
       console.log(limit);
       //formula;
       let skip=(page-1)*limit;
       const total=await STUDENT.countDocuments();
        const Data = await STUDENT.find().skip(skip).limit(limit);
        //res.send(Data);
        res.status(200).json({
            Data,
            limit,
            page,
            total
        });
    }
    catch (e) {
        res.status(500).send(e);
    }
})


// ..........

Comments

Popular posts from this blog

interview questions js[ Anurag Singh ProCodrr]

reactnative_creation