Firebase rest API 过滤器查询 [英] Firebase rest API filter query
问题描述
我的数据看起来像
{
"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."level" 之类的操作?我怎么能得到这些数据
is it possible to do something like $key."level" as in MongoDB ? and how could i get these data
推荐答案
您可以使用以下方法按属性排序:
You can order by a property using:
https://words-b6651.firebaseio.com/DE-EN.json?orderBy="level"&print=pretty
两个注意事项:
- 您需要为您的 Firebase 安全规则添加索引:
".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 rest API 过滤器查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!