I am looking at the Firebase Cloud Firestore documentation for orderBy. When I try to execute this
var facultyQuery = facultyRef.where("department", "==", "Core Teacher").orderBy('bb_last_name', 'desc');
I get the error:
Error: Firestore: Operation was rejected because the system is not in a state required for the operation`s execution. (firestore/failed-precondition).
Both of these simpler cases work just fine:
var facultyQuery = facultyRef.orderBy('bb_last_name', 'asc');
var facultyQuery = facultyRef.where("department", "==", "Core Teacher");
But when I combine the where and the orderBy, something I have done before with other Firestore collections, it fails.
Here is a sample record:
You can do the following: const admin = require("firebase-admin"); const db = admin. firestore(); db. listCollections() .
If you have a very time-sensitive app, like online auctions where you can't have unpredictable delays (no one likes to lose because of something that we don't control), you shouldn't really use Firestore. You will have a hard time hiding the hiccups and you will only anger your users.
20 for multi-document reads, transactions, and batched writes. The previous limit of 10 also applies to each operation.
A subcollection is a collection associated with a specific document. Note: You can query across subcollections with the same collection ID by using Collection Group Queries. You can create a subcollection called messages for every room document in your rooms collection: collections_bookmark rooms. class roomA.
Tip for anyone that needs it,
If you've forgotten to create an index and are getting the above error, run adb logcat
and then attempt to load the data again - it usually gives you a URL link which will very kindly create the required index for you.
I encountered this same issue, and Frank van Puffelen's comment fixed it for me. You need to create a composite index for "department" and "bb_last_name". Since "department" uses the equality operator, it doesn't matter whether it is ascending or descending in your index.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With