Bug report in wixData.query.Next()

Hi there,

I just wanted here to report a bug that I have found working on a wixdata query, dealing with pages.

Here is what I found:

First let’s describe the feature available in velo.
When you use wixData.query, the result doesn’t contain all the records of the collection. There is indeed a limit. The default limit is 50, which can be extended to x using “.limit(x)” in your query, with a maximum of 1000.

If there are more records to retrieve than that limit, you can use some properties and functions to get other records: hasNext(), next(), totalPages and currentPages. This is really nice and simple to use.

Simple example:

you have a collection with 120 records.
you launch a query with the default limit (i.e. 50).

This means that you will have 3 pages:

  • First execution of the query returns Page 0 that contains 50 records (hasNext() = true)
  • Execute .next() returns Page 1 : 50 records (hasNext() = true)
  • Execute .next() returns Page 2 : 20 records (hasNext() = false as it is the last page)

What we should have also is theses values:

  • First execution of the query should return : currentPage = 0, totalPages = 3, count = 50
  • Execute .next() should return : currentPage = 1, totalPages = 3, count = 50
  • Execute .next() should return : currentPage = 2, totalPages = 3 (last page), count = 20

Here is what I found:

If you explicitly set the .limit() parameter, it works perfectly.

On the other hand, if you rely on the default limit property without explicitly writing it, here the result:

  • First execution of the query returns : currentPage = 0, totalPages = 3, count = 50
  • Execute .next() returns : Page 1 : currentPage = 1, totalPages = 3, count = 50
  • Execute .next() returns : Page 2 : totalPages = 6, count = 20

On the last page, the property “currentPage” is not provided and the property “totalPages” has been recalculated based on the number of records of this last page (here count = 20 : 120 / 20 = 6) instead of being calculated based on 50, the default limit.

I hope that this could help developer not losing time debugging (as it took to me) and help the Wix team to correct that issue.

Cheers.