Can I query a Cloud Firestore collection with a where equals clause and an orderby?

|▌冷眼眸甩不掉的悲伤 提交于 2020-06-10 15:09:04

问题


The documentation states:

However, if you have a filter with a range comparison (<, <=, >, >=), your first ordering must be on the same field:

That implies that I can use the non-range comparison, "==", with the orderBy clause. But this fails:

myCollectionRef.where('age', '==', 2).orderBy('name');

回答1:


If you wanted to order a query with one or more equality filters, where the ordering is by a different field, you'll need to create a composite index.

You can read more about this in our "Managing Indexes" documentation section.



来源:https://stackoverflow.com/questions/46821757/can-i-query-a-cloud-firestore-collection-with-a-where-equals-clause-and-an-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!