使用 orderByChild 和 equalTo 卷曲 Firebase?

big*_*can 3 curl firebase

我正在尝试使用 REST API 来查询 Firebase(目前仅使用 curl)。

我尝试使用orderByChild返回结果的查询进行查询,但它们似乎没有排序。

curl -k 'https://shining-fire-6711.firebaseio.com/todos.json?orderByChild="name"'
Run Code Online (Sandbox Code Playgroud)

我也尝试orderByChildequalTo子句结合使用,但这只会返回错误orderBy must be defined when other query parameters are defined

curl -k 'https://shining-fire-6711.firebaseio.com/todos.json?orderByChild="name"&equalTo="c"'
Run Code Online (Sandbox Code Playgroud)

Win*_*ton 6

根据Firebase 文档

除非您使用 REST API,否则开发不需要索引。实时客户端库可以在不指定索引的情况下执行即席查询。性能会随着您查询的数据的增长而降低,因此如果您预计要查询大量数据,那么在启动应用程序之前添加索引非常重要。

这份文件藏在某个很深的地方,我花了好几个小时才找到它。

另外执行一些示例(从另一个 Firebase Document 获得)。我尝试在控制台上运行以下代码

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

它返回一些数据。这是返回值的一部分

{
  "linhenykus" : {
    "appeared" : -85000000,
    "height" : 0.6,
    "length" : 1,
    "order" : "theropoda",
    "vanished" : -75000000,
    "weight" : 3
  }
}
Run Code Online (Sandbox Code Playgroud)

它表明您不需要使用参数orderByChild,使用orderBy就可以了。