[英]How to conditionally apply a filter to a Firestore query with JavaScript
[英]How to apply filter on an array in a collection in firestore
我想过滤出用户标记的唯一内容,数据的结构在下面共享
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")
有什么方法可以对集合内的数组项应用过滤器? 在这方面的任何帮助将不胜感激。
{
title: "My great post",
categories: [
"technology",
"opinion",
"cats"
]
}
使用上面的数据结构,无法执行此查询。
考虑这种替代数据结构,其中每个类别都是映射中的键,所有值均为true:
{
title: "My great post",
categories: {
"technology": true,
"opinion": true,
"cats": true
}
}
参考链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.