繁体   English   中英

“获取文档时出错:FirebaseError:找不到匹配的索引。” — 尝试在两个字段上使用 WHERE 子句

[英]“Error getting documents: FirebaseError: no matching index found.” — trying to use WHERE clause on two fields

我正在尝试在两个字段上使用 where 子句。 我很惊讶地发现我不能在两个不同的字段上使用不等式子句,但我已将子句更改为使用“in”,并尝试了以下操作:

await db.collection("Colours").where("beta", "in", [3, 4, 5, 6]).where("alpha, "!=", [])
  .get()
...

并且不再得到不等式错误,但确实得到这个:

Error getting documents:  FirebaseError: no matching index found.

有没有办法解决? 我真的很失望,我似乎无法使用两个 where 子句! 另一种方法是在客户端进行过滤,但这需要从第一个子句中读取所有内容,对吗? 我的数据有很多文档,它会导致大量 Firestore 读取,我试图避免这种情况。

有一个关于这个的 GitHub 问题。 https://github.com/firebase/firebase-js-sdk/issues/5152

您需要为此在 Firestore 中创建索引。 在您的 Firebase 控制台中,前往 Firestore 并切换到“索引”选项卡。 然后新建一个复合索引,如下图:

在此处输入图片说明

确保您的集合名称和字段名称正确且大小写正确。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM