Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.
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

Closed

Description

@shiva-6

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.

Activity

  1. dconeybe commented on Oct 19, 2022

    @dconeybe
    Contributor

    Please provide a concrete example.

  2. self-assigned this
    on Oct 19, 2022
  3. shiva-6 commented on Oct 20, 2022

    @shiva-6
    Author

    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.

  4. dconeybe commented on Oct 20, 2022

    @dconeybe
    Contributor

    Ok I've reproduced the bug. You have definitely found an issue. I'll post back when I have a fix.

  5. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Oct 20, 2022
  6. dconeybe commented on Oct 22, 2022

    @dconeybe
    Contributor

    This bug has been fixed by #1072. It will be included in the next release. Thank you for your bug report!

  7. dconeybe commented on Oct 24, 2022

    @dconeybe
    Contributor
  8. partapu commented on Oct 26, 2022

    @partapu

    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.

  9. cherylEnkidu commented on Oct 26, 2022

    @cherylEnkidu
    Contributor

    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) with endAt(10).

  10. partapu commented on Oct 26, 2022

    @partapu

    Thanks for the confirmation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the googleapis/java-firestore API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions