我有一个带有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)