javascript - 如何在 AngularFire Firestore 中获取使用 .add() 创建的文档的 ID?
问题描述
我有这个代码
this.angularFirestore.collection<Loja>("lojas").add(loja)
.then(data => {
console.log(data);
});
我需要获取最近创建文档的文档 ID。我无法从数据变量中获取它...
解决方案
您需要将文档 ID 的创建与文档的编写分开:
const id = this. angularFirestore.createId();
this.angularFirestore.collection<Loja>("lojas").doc(id).set(loja)
另见:
- 关于存储文档 ID的 AngularFire 文档
推荐阅读
- wpf - 动画用户控件
- javascript - React 中的 Konva 无限网格
- ruby-on-rails - 更新 Amazon RDS SSL/TLS 证书 - Elastic Beanstalk
- kubernetes - 在 Kubernetes 中命名服务会阻止它启动
- c# - 在 Net Core 3.0 中同时使用 GRPC 通道
- javascript - 如何验证/阻止缩短字符串中的 URL
- python - Travis 收集...命令“pytest”以 1 退出
- excel - 范围内的 PowerQuery 范围
- linux - Linux 中给定命令的 CPU 利用率
- python - 创建知道每个列表长度的子列表