Firebase Firestore-多个动态where查询

时间:2019-06-08 20:50:54

标签: javascript firebase google-cloud-firestore angularfire2

在我的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并找到包含poststopic xtopic y的{​​{1}} ... < / p>

0 个答案:

没有答案