问题
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