在Firebase中使用.indexOn嵌套键 [英] Using .indexOn with nested keys in Firebase

查看:146
本文介绍了在Firebase中使用.indexOn嵌套键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆键,我想索引使用 .indexOn



假设我的数据看起来像下列。我希望能够使用 .orderByChild(height)

 lambeosaurus:{
stats:{
height:2.1,
length:12.5,
weight:5000


$ stegosaurus $ {
stats:{
height:4,
length:9,
weight:2500
}
}
}

我如何指定用于索引的规则 height ,它是 stats 的子项。我必须重新调整或压扁我的数据吗?

解决方案

您现在可以任意深入地查询和编制索引。

  {
rules:{
$ dinosaur:{
indexOn:[stats / height]
}
}
}

和嵌套值查询:

  .orderByChild('stats / height')


I have a a bunch of keys that i want to index using .indexOn

Suppose my data looks like the following. I want to be able to use .orderByChild("height").

{
  "lambeosaurus": {
    "stats": {
      "height" : 2.1,
      "length" : 12.5,
      "weight": 5000
    }
  },
  "stegosaurus": {
    "stats": {
      "height" : 4,
      "length" : 9,
      "weight" : 2500
    }
  }
}

How wound I specify the rule for indexing height which is a child of stats? Do I have to restructure or flatten my data?

解决方案

You can query and index arbitrarily deep now.

{
  "rules": {
    "$dinosaur": {
      ".indexOn": ["stats/height"]
    }   
  }
}

and query on nested values:

.orderByChild('stats/height')

这篇关于在Firebase中使用.indexOn嵌套键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆