【发布时间】:2020-08-10 18:10:12
【问题描述】:
我正在尝试弄清楚如何在 Firestore 的以下目录中构建一个新的子集合(红色圆圈):
目录:“课程/{userID}/{courseID}”
courseID 是在“userID”文档中创建子集合时随机生成的 ID。不幸的是,我能够使用 .set() 的代码不会创建新的子集合,而只是更新当前文档。
有没有可以用来在文档中创建新集合的函数?
代码:
export const createCourse = (course) => {
(...)
//firestore.collection("courses").doc(authorId).set({ <---This commented out line updates the document, yet I'm trying to construct a new sub-collection inside this document, not just change fields inside of it.
firestore.collection("courses").doc(authorId).add({ <--- This gives me an error stating " firestore.collection(...).doc(...).add is not a function ". I am trying to figure out what is the correct syntax for this intended action.
...course,
authorUID: authorId,
courseCreatedAt: new Date()
}).then(() => {
(...)
};
【问题讨论】:
标签: javascript firebase google-cloud-firestore