I am trying to get the newly created firestore document id and use it in the same cloud function, but am getting some error!
Here is my cloud function:
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';
});
When calling the function, I get this error in my functions log:
createNewGroup
Unhandled error TypeError: admin.firestore(...).collection(...).set is not a function
Not sure what I am doing wrong, and how to accomplish this?!?! Hoping for help and thanks in advance :-)