简体   繁体   English

如何在Firestore中的集合上的数组上应用过滤器

[英]How to apply filter on an array in a collection in firestore

I want to filter out the only content which is book marked by user, the structure of the data is shared below 我想过滤出用户标记的唯一内容,数据的结构在下面共享

卡扣已连接

 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 }; }); }); 

I think i'm making mistake here 我想我在这里犯错了

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

Is there any way I can apply filter on array items inside a collection? 有什么方法可以对集合内的数组项应用过滤器? any help in this regards will be highly appreciated. 在这方面的任何帮助将不胜感激。

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

With the data structure above, there is no way to perform this query. 使用上面的数据结构,无法执行此查询。

Consider this alternative data structure, where each category is the key in a map and all values are true: 考虑这种替代数据结构,其中每个类别都是映射中的键,所有值均为true:

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

Reference Link 参考链接

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

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