I'm trying to store an object to Firestore. My object contains 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" },
},
],
}
If this object is hard-coded into the Cloud Function it lets me save it to Firestore without failing. If I replace the array of the above object with a variable like so it still works:
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 above array is not hard-coded into the Cloud Function but created by my program, it fails. This is the code that generates the array:
const bikeBoxPriceArray = [];
for (let i = 0; i < bikeBoxPermissionArray.length; i += 1) {
const doc = bikeBoxPermissionArray[i];
// I cut out the stuff that is not important
const bikeBoxPriceArrayElement = {
permission: {
id: doc.id,
name: doc.name,
},
price: {
id: priceId,
unlock: priceUnlock,
firstHour: priceFirstHour,
twoHours: priceTwoHours,
final: priceFinal,
},
};
bikeBoxPriceArray.push(bikeBoxPriceArrayElement);
}
I verified with bikeBoxPriceArray instanceof Array
that it is indeed an array. What am I doing wrong? I tried out many many things but I just cannot figure it out. Why is it working when hard-coded but not with the variable?
The code is inside of a Firebase Transaction and there is no error message, it just tells me the location of the error.