firebase - Flutter 和 Firestore:如何从 add 函数中获取文档 ID?
问题描述
我向 Firestore 添加了一个文档。如何获取我添加的文档的文档 ID?我想将它保存到一个变量中。
顺便提一句。如果这很重要,我将其用于网络应用程序。
FirebaseFirestore.instance.collection('room').add({
'name': _name,
'points': 0,
});
解决方案
最后添加.then
方法。
使用 docRef 做任何你需要的事情。
FirebaseFirestore.instance.collection('room').add({
'name': _name,
'points': 0,
}).then(function(docRef) {
console.log("Document written with ID: ", docRef.id);
})
推荐阅读
- javascript - 我可以复制简单的对象结构并将 obj[prop] 选择符号与 Python 中的类一起使用吗?
- python - 图像未使用 PIL 加载到 tKinter 窗口中
- nestjs - 哪里更好地保留常用功能?
- c# - 发布到本地 IIS 时出现服务器错误 - Global.asax
- c# - 在 Linux .net 核心上的 IBM.MQ MQQueueManager 期间安全握手失败
- here-api - 此处地理编码:无法按加拿大邮政编码搜索
- javascript - 如何将 mat-button-toggle-group 设为只读模式
- r - 如何让闪亮的输入相互观察和重置
- vue.js - Vue 2 避免直接改变道具,因为该值将被覆盖
- javascript - 在另一个函数中访问映射对象