You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 30, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 30, 2026. It is now read-only.
LimitToLast with start and end cursors is not working as expected #1068
While querying with cursors and limiting them, limit api works as expected but limitToLast provides unexpected results. similar inconsistencies are visible in the combination of limitToLast and offset.
Query query = locations.orderBy("rating").endBefore(4.1);
In my collection locations, this query returns 31 documents as ordered. Also with limit,
locations.orderBy("rating").endBefore(4.1).limit(3);
I get the top 3 results which is perfect but when I use limitToLast I expect to get the last 3 but I get none, an empty list. Similar thing is happening with all startAt, endAt, endBefore and startAfter API's.
Hey, similar inconsistencies are visible in the combination of limit & limitTolast
Example:
query=locations.orderBy("rating").limit(10).limittolast(3);
My location's collection has 82 records, The above query returns the documents numbered 80,81, and 82. Since we are using the limit(10) along with limittolast(3) it should return 8,9,10 documents.
The firestore doesn't support use both limit and limitToLast in the same query. They are mutually exclusive. Whatever the last one is that you specify is the one that takes effect. In your case you need to achieve the desired result in two steps or replace limit(10) with endAt(10).
Activity
dconeybe commentedon Oct 19, 2022
Please provide a concrete example.
shiva-6 commentedon Oct 20, 2022
Query query = locations.orderBy("rating").endBefore(4.1);
In my collection locations, this query returns 31 documents as ordered. Also with limit,
locations.orderBy("rating").endBefore(4.1).limit(3);
I get the top 3 results which is perfect but when I use limitToLast I expect to get the last 3 but I get none, an empty list. Similar thing is happening with all startAt, endAt, endBefore and startAfter API's.
dconeybe commentedon Oct 20, 2022
Ok I've reproduced the bug. You have definitely found an issue. I'll post back when I have a fix.
dconeybe commentedon Oct 22, 2022
This bug has been fixed by #1072. It will be included in the next release. Thank you for your bug report!
dconeybe commentedon Oct 24, 2022
FYI v3.7.0 has been released with the fix:
https://central.sonatype.dev/artifact/com.google.cloud/google-cloud-firestore/3.7.0
#1067
partapu commentedon Oct 26, 2022
Hey, similar inconsistencies are visible in the combination of limit & limitTolast
Example:
query=locations.orderBy("rating").limit(10).limittolast(3);
My location's collection has 82 records, The above query returns the documents numbered 80,81, and 82. Since we are using the limit(10) along with limittolast(3) it should return 8,9,10 documents.
cherylEnkidu commentedon Oct 26, 2022
Hi @partapu ,
The firestore doesn't support use both limit and limitToLast in the same query. They are mutually exclusive. Whatever the last one is that you specify is the one that takes effect. In your case you need to achieve the desired result in two steps or replace
limit(10)withendAt(10).partapu commentedon Oct 26, 2022
Thanks for the confirmation