如何对firestore中的集合中的数组应用过滤器

时间:2018-03-27 11:57:04

标签: javascript ionic3 angular5 google-cloud-firestore angularfire2

我想过滤掉用户标记的唯一内容, 数据结构在

下面共享

snap is attached

this.contentList = afs.collection < Content > ('Content',
    ref =>
    ref.where('isActive', '==', true)

    .where("BookmarkedBy.UserID", "==", "hvC2WQL5JJG3Hbq1hxJe")
  )
  .snapshotChanges().map(actions => {
    return actions.map(a => {
      const data = a.payload.doc.data() as Content;
      data.$key = a.payload.doc.id;
      return { ...data
      };
    });
  });

我想我在这里弄错了

.where("BookmarkedBy.UserID","==" , "hvC2WQL5JJG3Hbq1hxJe")

有什么办法可以对集合中的数组项应用过滤器吗? 在这方面的任何帮助将受到高度赞赏。

1 个答案:

答案 0 :(得分:3)

{
    title: "My great post",
    categories: [
        "technology",
        "opinion",
        "cats"
    ]
}

使用上面的数据结构,无法执行此查询。

考虑这种替代数据结构,其中每个类别都是地图中的关键,所有值都为真:

{
    title: "My great post",
    categories: {
        "technology": true,
        "opinion": true,
        "cats": true
    }
}

参考Link