javascript - Firebase - IN 查询在 where 子句中不起作用,结果为空数组

标签 javascript firebase google-cloud-firestore

当我尝试使用 IN 查询过滤数据时,它没有向我显示结果,我在结果中得到一个空白数组,我在 firebase 控制台中尝试了同样的操作。我在那里也没有得到结果。

我的数据是 messages/01fjubNOf8oYODitr1h6 在此路径中,我有键 - 名称、消息、参与者

{
  name: "Pawan arora",
  message: "test",
  participants: ["33", "127"]
},
{
  name: "TEST NAME",
  message: "not working",
  participants: ["114", "127"]
}
{
  name: "TEST DATA",
  message: "new",
  participants: ["114", "33"]
}

我尝试在查询中过滤我的查询的数据

.collection("messages").where("参与者", "in", ["33", "127"])

这里我应该得到第一个对象作为结果

Firebase database image

最佳答案

过滤数组时需要使用array-contains-any运算符。

试试这个:

.collection("messages").where("participants", "array-contains-any", ["33", "127"])

详情查看this blogpost .

关于javascript - Firebase - IN 查询在 where 子句中不起作用,结果为空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65610942/

相关文章:

firebase - 列出 firestore 安全规则中的安全类型

javascript - 在表单的文本区域内选择时自动将单词转换为主题标签

java - 如何从服务器使用 Cloud Messaging Firebase 推送通知

java - Firebase 数据库数据收集

javascript - 如何停止警告 : It looks like you're using the development build of the Firebase JS SDK?

firebase - 如何检查Firestore文档中的数组是否为空?

android - 云 Firestore : can cache be read synchronously?

javascript - 通过连续点击按钮使 Canvas 的元素逐渐淡出

javascript - 参数未通过两级 JavaScript 构造函数传递

javascript - 为什么我会收到 ReferenceError : not defined