我可以使用where equals子句和orderby查询Cloud Firestore集合吗? [英] Can I query a Cloud Firestore collection with a where equals clause and an orderby?

查看:210
本文介绍了我可以使用where equals子句和orderby查询Cloud Firestore集合吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档指出:


但是,如果您有一个带范围比较的过滤器(<,< =,>,> =),您的第一个订购必须是相同的字段:

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

这意味着我可以使用非范围比较==和orderBy子句。但这失败了:

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

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


推荐答案

如果您想订购一个或多个查询等式过滤器,其中排序是由不同的字段,你需要创建一个复合索引。

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.

这篇关于我可以使用where equals子句和orderby查询Cloud Firestore集合吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆