GeoFire orderByChild过滤

时间:2018-04-16 23:16:40

标签: javascript angular firebase geofire

我似乎偶然发现了GeoFire的一个问题,因为我似乎无法过滤我的GeoFire查询。在我的平台上,用户创建帖子并使用geofire设置他们的位置,因此,有可能有数千个帖子我不想在客户端进行过滤..

我想orderByChild('created')limitToLast('10')所以在客户端不需要太长时间..

到目前为止我所拥有的是:

  this.geoFire = new GeoFire(this.database.database.ref()
  .child('location'))
  this.geoFire.query({
    center: [this.userLocation.lat, this.userLocation.lng],
    radius: 7
  })
  .on('key_entered', (key, location, distance) => {
    this.subscription = this.database.database.ref('/posts/'+key)
    .orderByChild('created')
    this.subscription.once('value', (snapshot) => {
          this.postFeed.push(snapshot.val())
    });
  })

但这似乎不起作用。

我的位置数据库如下所示:

enter image description here

和帖子:

enter image description here

我做错了什么?为什么我无法过滤orderByChild('score') or 'created'

1 个答案:

答案 0 :(得分:0)

Firebase查询根据您指定的条件从某个位置检索(可能)多个子节点。您已在此处拥有该帖子的完整路径:database.ref('/posts/'+key)。您无法通过根据条件查询要查找的帖子来结合已知的帖子。

这里最好的选择是检索范围内的所有帖子,然后过滤客户端上最近的10个帖子。

相关问题