Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onSnapshot orderBy doesn't work #2113

Closed
holtc opened this issue Aug 26, 2019 · 1 comment
Closed

onSnapshot orderBy doesn't work #2113

holtc opened this issue Aug 26, 2019 · 1 comment

Comments

@holtc
Copy link

holtc commented Aug 26, 2019

Environment

  • Operating System version: macOS Mojave 10.14.4
  • Browser version: Chrome Version 76.0.3809.100 (Official Build) (64-bit)
  • Firebase SDK version: 6.4.2
  • Firebase Product: Firestore

Problem

The orderBy query, when paired with onSnapshot, does not seem to work after updating to 6.4.2 from ^5.3.1. In the web console, this same orderBy query displays the docs in the correct order.

Steps to reproduce:

Create a collection named collection and create an index on createdAt, to be ascending, where createdAt is a firebase.firestore.FieldValue.serverTimestamp()

Relevant Code:

firestore.collection('collection')
    .orderBy('createdAt', 'desc')
    .onSnapshot(async querySnapshot => {
        querySnapshot.docs.forEach(doc => {
            // These docs are not in the correct order
        })  
    })
@var-const
Copy link
Contributor

I have tried the code snippet from above, and it produces the docs sorted by createdAt field in descending order. This is to be expected, because the orderBy is specified to use desc order. Indexing is largely orthogonal to this, and an existing index will not override the order specified in orderBy. Is this different from the results you're seeing? If so, can you please post the values of createdAt for the documents returned by your query in the order returned? For example, the order I'm seeing is:

createdAt: io {seconds: 1566851621, nanoseconds: 195000000}
createdAt: io {seconds: 1566851621, nanoseconds: 13000000}
createdAt: io {seconds: 1566851620, nanoseconds: 791000000}

@holtc holtc closed this as completed Aug 28, 2019
@firebase firebase locked and limited conversation to collaborators Oct 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants