I am attempting to save an object to Firestore which includes an array:
{
returnMode: false,
id: "SE-74c5219a-acfe-4185-9e33-f78b10ac3f1e",
prices: [
{
price: {
twoHours: 0,
firstHour: 0,
id: "zero",
unlock: 0,
final: 0,
},
permission: { id: "GENERAL" },
},
{
price: {
twoHours: 150,
unlock: 100,
id: "oebb_low",
firstHour: 50,
final: 50,
},
permission: { id: "OEBB" },
},
],
}
When I hard-code this object into the Cloud Function, it successfully saves to Firestore without any issues. However, if I replace the array in the object with a variable like this, it continues to work:
const array = [
{
price: {
twoHours: 0,
firstHour: 0,
id: "zero",
unlock: 0,
final: 0,
},
permission: { id: "GENERAL" },
},
{
price: {
twoHours: 150,
unlock: 100,
id: "oebb_low",
firstHour: 50,
final: 50,
},
permission: { id: "OEBB" },
},
];
{
returnMode: false,
id: "SE-74c5219a-acfe-4185-9e33-f78b10ac3f1e",
prices: array,
}
However, when the array is dynamically generated by my program rather than hard-coded, it fails to save. The following code snippet shows how the array is created:
const bikeBoxPriceArray = [];
for (let i = 0; i < bikeBoxPermissionArray.length; i += 1) {
const doc = bikeBoxPermissionArray[i];
const bikeBoxPriceArrayElement = {
permission: {
id: doc.id,
name: doc.name,
},
price: {
id: priceId,
unlock: priceUnlock,
firstHour: priceFirstHour,
twoHours: priceTwoHours,
final: priceFinal,
},
};
bikeBoxPriceArray.push(bikeBoxPriceArrayElement);
}
I have confirmed using
bikeBoxPriceArray instanceof Array
that it is indeed an array. What could be causing this issue? I have tried various solutions but cannot seem to identify the problem. Why does it work when hard-coded but not with a variable?
This code is executed within a Firebase Transaction and no error message is displayed, just the location of the error.