skip to Main Content
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


  1. You can pass limit method after student.find(). For example if you want to limit 10 documents it’ll look like this const result = student.find().limit(10)

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. You can specifify a limit and an offset for your query by using skip() and limit():

    const page = 1;
    const itemsPerPage = 10;
    
    const result = await student.find().skip(page * itemsPerPage).limit(itemsPerPage);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search