const result = student.find();
In mongodb database i require to get 10 documents on every buttion click and next time on click i need to get net 10 documents in mongodb.
const result = student.find();
In mongodb database i require to get 10 documents on every buttion click and next time on click i need to get net 10 documents in mongodb.
3
Answers
You can pass limit method after
student.find()
. For example if you want to limit 10 documents it’ll look like thisconst result = student.find().limit(10)
Follow below steps –
Step 1 – Pass limit and skip value in api query like –
baseurl/api/v1/apiendpoint?limit=10&skip=0
Step 2 – Fetch limit and skip value from url
const limit = req.query.limit;
const skip = req.query.skip;
step 3 –
const result = student.find().skip(skip).limit(limit);
Note – Limit and skip value will be change as per your click.
You can specifify a limit and an offset for your query by using
skip()
andlimit()
: