【发布时间】:2020-04-07 20:55:47
【问题描述】:
我是 Angular 新手,但我遇到了问题。我不知道如何获取我刚刚创建的文档 ID 并在它旁边使用它。我看到有db.collection('info').doc().set()和db.collection('info').add()两个选项。
目前我已经尝试过这段代码:
var DocID:string;
db.collection().add({
description: info
}).then(function(docRef){
DocID = docRef.id;
}).catch(function(error){
console.log("Error creating the document:", error);
});
IdInfo.push(DocID);
我需要将文档中的所有 Id 存储在数组中,尽管有时我完成了它,而其他时候我收到错误 undefined。我不知道哪种方法是创建新文档并向其添加数据并接收文档 ID 的最佳方式。
谢谢你的帮助!!
块引用
【问题讨论】:
标签: angular firebase ionic-framework google-cloud-firestore