admin管理员组文章数量:1302888
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 bine the where and the orderBy, something I have done before with other Firestore collections, it fails.
Here is a sample record:
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 bine the where and the orderBy, something I have done before with other Firestore collections, it fails.
Here is a sample record:
Share Improve this question edited Dec 11, 2017 at 1:25 Frank van Puffelen 600k85 gold badges889 silver badges859 bronze badges asked Dec 11, 2017 at 1:15 AdamGAdamG 2,6303 gold badges25 silver badges39 bronze badges 3-
Did you create the necessary index on
department
andbb_last_name
? You should get a better error message than this if you forgot, but I'd like to make sure. – Frank van Puffelen Commented Dec 11, 2017 at 1:28 - I did not. The documentation states that "...queries that only use equality clauses don't need additional indexes" so I did not think I needed one. firebase.google./docs/firestore/query-data/indexing – AdamG Commented Dec 11, 2017 at 1:39
-
It's the additional
orderBy
that makes me think it might. But it would usually give a very clear message about that. – Frank van Puffelen Commented Dec 11, 2017 at 2:04
2 Answers
Reset to default 7Tip 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 ment fixed it for me. You need to create a posite 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.
本文标签:
版权声明:本文标题:javascript - Firebase Firestore: orderBy combined with where causes error "Operation was rejected" - Stack Ove 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741685536a2392421.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论