Firebase REST orderby自动生成ID的嵌套子级? [英] Firebase REST orderby nested child of autogenerate ID?

查看:28
本文介绍了Firebase REST orderby自动生成ID的嵌套子级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何请求嵌套子项的Firebase订单?我的示例数据如下:

How do I request firebase orderby nested child? My example data look like this:

ROOT
 |
 +-- post
 |     |
 |     +-- -LHRgRaBkEbh2J04sZcM
 |            |
 |            +-- vote: 1
 |     +-- -LHRgqbaxDTa5Jl6Wdar
 |            |
 |            +-- vote: 2
 |     +-- -LHRtsJhu4yl1vi4JS2X
 |            |
 |            +-- vote: 3
 |

根据firebase文档,您可以这样做:

According to firebase docs you can do it like this:

curl 'https://dinosaur-facts.firebaseio.com/dinosaurs.json?orderBy="dimensions/height"&startAt=3&print=pretty'

但是我不能这样做,因为父节点是自动生成的.

but I can't do this since the parent node is autogenerated.

orderBy="parent/vote"

我该如何克服?

推荐答案

Firebase数据库查询将每个子节点置于您查询的位置下方,然后在您指定的属性上对其进行排序.因此,他们会在您查询的位置下自动跳过一个级别.

Firebase Database queries take each child node under the location you query, and then order them on the property you specify. So they automatically skip a single level, under the location you query.

curl 'https://your-db.firebaseio.com/post.json?orderBy="vote"&startAt=3&print=pretty'

请注意,此返回正确的结果(从 3 开始),但结果将排序(因为JSON中的键)根据定义是无序的.

Note that this will return the correct results (starting at 3), but the results will not be ordered (since keys in JSON are by definition unordered).

这篇关于Firebase REST orderby自动生成ID的嵌套子级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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