【发布时间】:2021-11-15 23:04:21
【问题描述】:
以前在 Firebase 中,您可以像这样添加文档:
const myNewDoc = await db.collection('some-collection-name').add({ //Document details here... });
随着 Firebase 9 的推出,这不再有效。
我想我应该使用导入的.addDoc 方法而不是.add。
但我似乎无法将.addDoc 链接到.collection。
如果我尝试做这样的事情:
const myNewDoc = await db.collection('some-collection-name').addDoc({ //Document details here... });
TypeScript 抛出此错误:
Property 'addDoc' does not exist on type 'CollectionReference<DocumentData>'.ts(2339)
我可以像这样创建更详细的内容:
const someCol = collection(db, "some-collection-name");
const newDoc = await addDoc(someCol, {
//Document details here...
});
但我宁愿像以前一样“链接”它。
这可能吗?怎么做?
我什至应该使用.addDoc 吗?还是别的什么?
【问题讨论】:
标签: javascript firebase google-cloud-firestore