【发布时间】:2021-11-01 20:09:36
【问题描述】:
我正在尝试获取新创建的 firestore 文档 ID 并在同一个云功能中使用它,但出现了一些错误!
这是我的云功能:
exports.createNewGroup = functions.https.onCall((data, context) => {
if (!context.auth) {
throw new functions.HttpsError(
'unauthenticated',
'only autehnticated users can make requests!'
);
}
// Save a new group document and get the documents ID
const { id } = admin.firestore().collection('groups').set(data.group);
// Adding the group id to the groupmember object
data.groupMember.groupId = id;
// Save a new groupmember document with the newly created groupid added
admin.firestore().collection('groupMembers').set(data.groupMember);
return 'All is created perfectly';
});
调用函数时,我的函数日志中出现此错误:
createNewGroup
Unhandled error TypeError: admin.firestore(...).collection(...).set is not a function
不知道我做错了什么,以及如何做到这一点?!?!希望得到帮助和提前感谢:-)
【问题讨论】:
标签: javascript node.js firebase google-cloud-functions firebase-admin