question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

firestore order by with where class does not work

See original GitHub issue

orderby is not working ? All latest versions

does not work
let query = citiesCollection.where("state", "==", "CA").orderBy("population", "desc").limit(2); does not work
let query = citiesCollection.where("state", "==", "CA").orderBy("population").limit(1); does not work
let query = citiesCollection.where("state", "==", "CA").orderBy("state").limit(1);

Works let query = citiesCollection.where("state", "==", "CA").limit(2); Works let query = citiesCollection.limit(2);

Thanks, Narayan

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
Ravi2908commented, May 31, 2019

The problem is you need to create an index for your where and orderBy condition in the indexes column in your cloud firestore.

By creating indexes you will be able to fetch the record using where and orderBy

8reactions
narayananl23commented, Jan 24, 2018

Thanks @EddyVerbruggen. Sharing my finding, so it can help others.

Copying the code from the demo ng helped. Since I am using non angular, I did not look at the sample at first and non angular do not have firestore sample.

I was using https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/FIRESTORE.md "Ordering and limiting results of collection.where() " from the firestore doc page.

When I used the angular, I found that I do not have index. When I posted the issue, I did not have error handling so I got lost.

CONSOLE LOG firestoreWhereOrderLimit failed, errorThe query requires an index. You can create it here: https://console.firebase.google.com/project/xxxxxx/database/firestore/indexes?create_index=xxxxxxxx

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase Firestore order by not working - Stack Overflow
This is happening because of nested queries. If you put a query inside a listener (success/failure/complete), orderBy method will not work.
Read more >
Order and limit data with Cloud Firestore | Firebase - Google
Order and limit data ... By default, a query retrieves all documents that satisfy the query in ascending order by document ID. You...
Read more >
Ordering and limiting Firestore queries in descending order
Stay organized with collections Save and categorize content based on your preferences.
Read more >
Cloud Firestore - React Native Firebase
The collection method returns a CollectionReference class, which provides properties and methods to query and fetch the data from Cloud Firestore. We can...
Read more >
Cloud Firestore | FlutterFire
A DocumentSnapshot is returned from a query, or by accessing the document directly. Even if no document exists in the database, a snapshot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found