Firebase REST orderby nested child of autogenerate ID?

别说谁变了你拦得住时间么 提交于 2021-01-28 10:40:37

问题


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
 |

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"

How can I overcome this?


回答1:


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'

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).



来源:https://stackoverflow.com/questions/51382047/firebase-rest-orderby-nested-child-of-autogenerate-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!