Backend query and results.next() problem

Hi,
i have a data query function at the backend with limit(4) as an example that returns the results.
when I want to get the next page with results.next().then… It says next() isnt a function.
as long as I declare the data query function on page code it works perfectly.

Can anybody explain why and give a solution ?

Hey
If you set limit(4) you have defined the size of the result. If you want to call that function from frontend code but get the next 4 items you need to make the function accepting startIndex and Limit so you can ask the function to get the next 4 items for you. The results you get back to your frontend code only consists of an array with four items, it is not a property that holds functions like .next().

export function getItems(limitItems, offsetItems) {
  wixData.query("DataCollectionName")
  .limit(limitItems)
  .skip(offsetItems)
  .find()
  .then((results) => {
    if (results.totalCount > 0) {
      return results.items;
    }
    return null;
  })
}

So call that backend function by using

getItems(4,0).then((myItems) => {
  console.log(myItems); //will be first 4 items
})

getItems(4,4).then((myItems) => {
  console.log(myItems); //will be next 4 items
})

So you work with the skip property to get to a certain page when working with backend code. Or I do at least, that does not mean it is the way to do it :slight_smile:

I hope it helps you.