Let's say, I need to send an email to all the members of the group when the group is complete:
export const sendEmailToNewMember = functions.firestore.document('group/{groupId}').onCreate(async (snapshot,context) => {
}
The collection group has subcollection members. I check if the member's count has incremented and matches the total number of members who can join a group. If the final member has joined, I need to send all the members an email saying the group is complete.
The data structure looks like the one shown below:
collection group {
membersCount: 9999,
totalMembers: 100000,
....
users subcollection
}
I tried accessing the collection through ref like so:
const usersRef = snap.ref.collection('users)
But, the result was undefined. For now, I access it using
await firestore().collection('group').doc(groupId).collection('users')
Is it possible to access the subcollection without awaiting it and from the snapshot itself?