如何仅在 Firebase 中获取子密钥 [英] How to only get child keys in Firebase

查看:16
本文介绍了如何仅在 Firebase 中获取子密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想显示位置的孩子,即信德和旁遮普(不是他们的孩子).有可能吗,如果有,我该怎么做?

I want to display only children of location i.e Sindh and Punjab (not their children). Is it possible, and if so how can I do it?

推荐答案

来自 文档中的数据结构最佳实践:

避免嵌套数据

因为 Firebase 实时数据库允许最多嵌套 32 个数据深层次,你可能会认为这应该是默认结构.但是,当您在您的某个位置获取数据时数据库,您还可以检索其所有子节点.此外,当您授予某人对数据库中某个节点的读或写访问权限,您还授予他们访问该节点下所有数据的权限.因此,在实践中,最好使您的数据结构尽可能扁平.

Because the Firebase Realtime Database allows nesting data up to 32 levels deep, you might be tempted to think that this should be the default structure. However, when you fetch data at a location in your database, you also retrieve all of its child nodes. In addition, when you grant someone read or write access at a node in your database, you also grant them access to all data under that node. Therefore, in practice, it's best to keep your data structure as flat as possible.

Firebase 就是这样工作的:如果你得到一个项目,你也会得到它的子项.如果你不想这样,你应该重构数据库.

That is how Firebase works: If you get an item, you get its children as well. If you don't want this, you should restructure the database.

这篇关于如何仅在 Firebase 中获取子密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆