Firebase 如何从云函数在cloud firestore中动态创建集合

Firebase 如何从云函数在cloud firestore中动态创建集合,firebase,google-cloud-firestore,google-cloud-functions,Firebase,Google Cloud Firestore,Google Cloud Functions,我正在尝试通过云函数为集合中的文档动态创建集合和子集合, 但我有以下例外 ** 参数“collectionPath”必须指向一个集合,但为 “数据/c2f7c4e84366”。您的路径不包含奇数个 组成部分 ** 日志- 错误:参数“documentPath”必须指向文档,但它是“exports/User3434\u inbox/profile”。您的路径不包含偶数个组件。 在Firestore.doc(/user\u code/node\u modules/firebase admin/nod

我正在尝试通过云函数为集合中的文档动态创建集合和子集合, 但我有以下例外 **

参数“collectionPath”必须指向一个集合,但为 “数据/c2f7c4e84366”。您的路径不包含奇数个 组成部分

**

日志-

错误:参数“documentPath”必须指向文档,但它是“exports/User3434\u inbox/profile”。您的路径不包含偶数个组件。 在Firestore.doc(/user\u code/node\u modules/firebase admin/node\u modules/@google cloud/Firestore/src/index.js:282:13) 位于admin.firestore.doc.set.then.ws(/user\u code/lib/index.js:28:53)

代码段: const p=admin.firestore().doc(
exports/${userInboxCollectionName}/profile
).set(reqData,{merge:false}) *


我希望云函数在exports集合(已存在)内动态创建子集合(userid_inbox)(如果不存在),并添加配置文件文档。

Firestore的工作方式如下:
collection/document/subcollection/“subDocument”/
等等

你应该试试:(我用的是TS)


使用此代码,您将在新的子集合上创建一个带有值消息的新文档。

请编辑您的问题,以显示生成此错误的代码。
let p = admin.firestore().collection(`exports/${userUID}/${theSubcollection}`)
    .add({ message: messageString })
    .then(ref => {
        console.log('Added document with ID: ', ref.id)
});

//let's see the estructure here:
//collection.......exports   
//document.........${userUID}
//subcollection....${theSubcollection}
//document.........ref.id
//data.............message with value messageString