firestore order by with where class does not work
See original GitHub issueorderby 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:
- Created 6 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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