How to get an array of 10 objects from api for pagination in react

Viewed 79

I have 40 products in mongodb, I want only 10 products in every page for pagination purpose, but I am getting all 40 records , backend is : nodejs , database is: MongoDB

x

[{id:1, name:'Apple},{id:2, name:'Orange},{id;4, name:'Mango'},{id;40, name:'Grapes},]
getProducts(page)
{

 axios.get(`${url}/products?_page=${page})
}

same logic working fine for placeholder webiste

1 Answers

N = how many object in one page

P = which page

db.collection.find({}).skip(P*N).limit(N)
Related