Firebase (2016) 浅层查询 [英] Firebase (2016) Shallow Query
问题描述
我正在试用 Firebase(从 Google 的新版本开始).
I'm trying out Firebase (since Google's new release).
在 Firebase 的原始版本中,参数 shallow=true
将返回一个带有 { key: true }
的对象,用于请求的树/分支根处的每个 key
(等等,而不是返回孩子,您只会知道 child(ren) 存在的事实).这很有用,因为您不一定想要来自子节点的所有数据(特别是如果有很多数据).
In the original version of Firebase the parameter shallow=true
would return an object with { key: true }
for every key
at the root of the tree/branch that was requested (and so, rather than children being returned, you would just know the fact that child(ren) exist). This is useful because you don't necessarily want all the data from the child nodes (particularly if there's a lot of it).
Google 的新版 Firebase 有没有办法做到这一点?我在想:
Is there a way to do that with Google's new version of Firebase? I'm thinking something like:
firebase.database().ref('/data/?shallow=true').once('value', function(snapshot) {
// do something with snapshot
}
上述代码的 snapshot.val()
返回 null,如果我正在阅读 文档 正确,此功能似乎已消失.
The above code's snapshot.val()
returns null and if I'm reading the docs correctly, it seems this functionality is gone.
推荐答案
Firebase Database 2.x 中的 ?shallow=true
参数仅在 REST API 中可用.请参阅 https://www.firebase.com/docs/rest/guide/retrieving-data.html#section-rest-uri-params.
The ?shallow=true
parameter in Firebase Database 2.x was only available in the REST API. See https://www.firebase.com/docs/rest/guide/retrieving-data.html#section-rest-uri-params.
在新的 Firebase Database 3.x 中,相同的参数仍然只在 REST API 中可用.请参阅 https://firebase.google.com/docs/database/rest/检索数据#shallow
In the new Firebase Database 3.x, the same parameter is still only available in the REST API. See https://firebase.google.com/docs/database/rest/retrieve-data#shallow
您使用的是从未支持此参数的 Firebase SDK(从它的外观来看是 JavaScript).
You're using a Firebase SDK (JavaScript from the looks of it), which never supported this parameter.
有关过去讨论过的更多问题,请参阅:
For more questions that have discussed this in the past, see:
- Firebase 检索子键而不是值
- 使用浅层数据的 Firebase REST API
- 如何在 Firebase 上进行浅查询iOS?
- 获取 Firebase 子级在 Firebase 响应中没有获取其子节点的节点名称?
这篇关于Firebase (2016) 浅层查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!