首页 > 解决方案 > 在 Firestore 中的对象数组中查询子项

问题描述

我正在尝试在我的 firestore 集合中查找数组字段的元素。

这是firestore中的字段:

channels: [{name: "linkedin", date: "2020-01-02"}]

这就是我尝试查询它的方式:

firebase.firestore().collection("users")
  .where("status", "==", "ACTIVE")
  .where("channels", "array-contains", {
      name: "linkedin"                     
  })

标签: firebasegoogle-cloud-firestore

解决方案


array-contains无法对对象的特定属性值执行搜索。

如果你做类似的事情,它会起作用channels: ["Linkedin", "facebook", "twitter"]

可能您想尝试对通道使用子集合,否则,您需要将所有值提取到通道中,然后在内存中应用过滤器。


推荐阅读