I have been attempting to get the params and data of a multi subcollection level structure in firebase. I need to know all the documentIds at each level. I am using the onCreate trigger.
I have a structure like below:
utilities/gas/paymentTypes/card/dates/2020-01
and have been attempting to get the following parameters:
- Utility Type e.g. gas
- Payment Type e.g. card
- Date e.g. 2020-01
The code I have been attempting to use is below:
export const addDistributionArea = functions.firestore.document("utilsTypesDistributionArea/{utilityType}/paymentTypes/{paymentType}/dates/{date}")
.onCreate(async (snapshot: any, context: any) => {
console.log("params", context.params);
console.log("id", snapshot.ref.id);
console.log("data", snapshot.data());
return null;
});
Currently I can retrieve utilityType and paymentType however {date} is always undefined.
Result:
> params { utilityType: 'gas', paymentType: 'card', date: undefined }
> id QDD_1
> data {}
Could anyone please help me with finding a solution.