firebase - 如何从 Firbase 数据库中获取特定数据
问题描述
飞镖
在 Firestore 中,我可以从字段所属的特定文档中获取特定的字段值,就像这样
final DocumentSnapshot doc = await FirebaseFirestore.instance.collection("users").doc(widget.documentUid).get();
String name = doc.get("name");
这在 Firebase 数据库中也可以实时吗?
我试过了,但没有选择doc.get("name");
FirebaseDatabase.instance.reference().child(currentUser.uid).then((snapshot) {
String jj = snapshot.value;
});
好的,可以说我这样设置数据
FirebaseDatabase.instance.reference().child("123").set({
"test1":"test"
});
然后我把它输入数据库
testapp-54-default-rtdb
123
test1": test
我怎样才能得到test field
属于123
唯一的
非常感谢您阅读我的问题
解决方案
获取路径的特定数据
FirebaseDatabase.instance.reference().child(currentUser.uid).child("ok")
.once().then((DataSnapshot snapshot) {
String jj = snapshot.value;
});
在您的情况下,这将返回“okkk”。
或者
FirebaseDatabase.instance.reference().child(currentUser.uid)
.once().then(( DataSnapshot snapshot) {
String jj = snapshot.value["ok"];
});
推荐阅读
- ios - CoreData + Cloudkit - 自动MergesChangesFromParent
- spring-boot - 无法打开 JPA EntityManager 进行事务处理;嵌套异常是 java.lang.NoSuchMethodError
- r - 插入带有文件名的列
- google-apps-script - Google 表单上的 Google 脚本,参考编号问题
- javascript - 异步函数没有按应有的顺序执行
- build - 如何在 LG WebOS TV 中安装 .IPK 文件?
- reactjs - ReactDOM.render 中的第二个参数是什么意思?
- postgresql - spring.datasource.password 的 Docker YAML 环境有符号。我该如何解决这个问题?
- .net-core - '{{FSharpCoreShippedPackageVersion}}' 不是有效的版本字符串
- jenkins - 使用 Jenkins 管道在不同节点上并行运行相同的阶段