在我的Firestore数据库中,我创建了posts
用户生成的topic
元素。
用户订阅主题,并将其存储在用户的个人资料数据库中。
现在,我需要遍历用户的所有已订阅主题,并且我想查找用户topic
对象中也有subscribed_to
的最新10条帖子。
所以我在做什么:
//establish the query.
var query = this.afs.collection('posts').ref
.orderBy('created', 'desc')
.limit(11);
//loop through the user's subscribed_to data
for(var topic in this.userData.subscribed_to) {
//add each topic to the where query
query = query.where('topic', '==', topic);
}
query.get().then((results) => {
//..rest of the code
})
问题似乎是,将where
添加为AND
而不是OR
的查询,这意味着post
将需要所有主题用户已订阅...
我该怎么做,它经过OR
并找到包含posts
或topic x
或topic y
的{{1}} ... < / p>