本文介绍了Firebase休息API过滤器查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据看起来像
{
"word0" : {
"level" : "B2",
"meaning" : [ "Meaning19", "meaning43" ],
"type" : "Noun",
"weight" : 0,
"word" : "word99"
},
"word1" : {
"level" : "C1",
"meaning" : [ "Meaning19", "meaning43" ],
"type" : "Noun",
"weight" : 0,
"word" : "word99"
},
"word10" : {
"level" : "A2",
"meaning" : [ "Meaning19", "meaning43" ],
"type" : "Noun",
"weight" : 0,
"word" : "word99"
}
}
我使用curl获取请求 https://words-b6651.firebaseio.com/DE-EN.json?orderBy=$ key& print = pretty
我想要获得一个给定级别的所有单词
i am using curl get request https://words-b6651.firebaseio.com/DE-EN.json?orderBy="$key"&print=pretty
and i want to get all words of a given level
是否可以像MongoDB一样执行像$ key。我如何获得这些数据
is it possible to do something like $key."level" as in MongoDB ? and how could i get these data
推荐答案
您可以通过属性订购:
https://words-b6651.firebaseio.com/DE-EN.json?orderBy="level"&print=pretty
两个注释:
- :
indexOn:level
-
JSON中的项目将处于未确定的顺序,因为JSON本质上是无序的。这意味着在REST API中的排序实际上仅在您也过滤数据时才有用。
- you'll need to add an index to your Firebase security rules:
".indexOn": "level"
the items in the JSON will be in an undetermined order, since JSON is inherently non-ordered. This means that ordering in the REST API is really only useful when you also filter the data, e.g.
https://words-b6651.firebaseio.com/DE-EN.json?orderBy="level"&equalTo="B2"&print=pretty
这篇关于Firebase休息API过滤器查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!