小编tok*_*ism的帖子

为什么这个 firestore 查询需要索引?

我有一个带有where()相等运算符的方法的查询,然后是一个orderBy()方法,但我无法弄清楚为什么它需要索引。where 方法检查对象(地图)中的值,order by 是一个数字。

文档说

如果您的过滤器具有范围比较(<、<=、>、>=),则您的第一个排序必须在同一字段上

所以我会认为平等过滤器会很好。

这是我的查询代码:

this.afs.collection('posts').ref
.where('tags.' + this.courseID,'==',true)
.orderBy("votes")
.limit(5)
.get().then(snap => {
  snap.forEach(doc => {
    console.log(doc.data());
  });
});
Run Code Online (Sandbox Code Playgroud)

这是数据库结构的示例 在此处输入图片说明

javascript firebase angularfire2 google-cloud-firestore

28
推荐指数
2
解决办法
2万
查看次数