我试图弄清楚如何在 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(() => {
(...)
};
慕村225694
POPMUISE
随时随地看视频慕课网APP
相关分类