Javascript 我可以构建一个子集合吗?(消防商店)

Javascript 我可以构建一个子集合吗?(消防商店),javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,我正试图找出如何在Firestore的以下目录中构造新的子集合(红色圆圈): 目录:“courses/{userID}/{courseID}” 在“userID”文档中创建子集合时,将随机生成courseID。不幸的是,我使用.set()能够运行的代码没有创建新的子集合,而只是更新当前文档 是否有一个函数可用于在文档中创建新集合 代码: export const createCourse=(课程)=>{ (...) //firestore.collection(“courses”).doc(a

我正试图找出如何在Firestore的以下目录中构造新的子集合(红色圆圈):

目录:“courses/{userID}/{courseID}”

在“userID”文档中创建子集合时,将随机生成courseID。不幸的是,我使用.set()能够运行的代码没有创建新的子集合,而只是更新当前文档

是否有一个函数可用于在文档中创建新集合

代码:

export const createCourse=(课程)=>{
(...)

//firestore.collection(“courses”).doc(authorId).set({您尝试执行的操作没有API。另外,使用随机集合名称来建模数据通常不是一个好主意。应用程序应该提前知道集合名称,因为:

  • 如果不知道集合的名称,则无法查询集合
  • 没有客户端API来列出文档下的子集合

  • 考虑改用名为“courses”的子集合,然后在下面添加一个带有随机ID的文档。

    一如既往,感谢您的澄清和建议Doug:)
    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(() => {
    
        (...)
    
    };