首页 > 解决方案 > Firebase - IN查询在where子句中不起作用,结果是空白数组

问题描述

当我尝试使用 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("participants", "in", ["33", "127"])

在这里我应该得到第一个对象

Firebase 数据库映像

标签: javascriptfirebasegoogle-cloud-firestore

解决方案


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

尝试这个:

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

有关详细信息,请查看此博文


推荐阅读