I came across an unusual behaviour of the function to upload Firestore documents. In the code below, the values that are updated in document are keyValue : valueValue instead of accessing the constants that store the desired fields to be updated in the Firestore document.
it throws an error: 'keyValue' is declared but its value is never read . That means the actual value "keyValue" is used instead of the constant keyValue.
Any advice?
function createObjectDocument(document: any, caseNumber: String)
{
document.get().then(function(doc: any) {
if (doc.exists) {
console.log("Document data:", doc.data());
for (let [key, value] of Object.entries(doc.data())) {
let keyValue = key;
let valueValue = value;
console.log(`${key}: ${value}`);
if (key != "CaseRefArray") {
db.collection("casesToExport").doc(caseNumber).update({
keyValue: valueValue
})
.then(() => {
console.log("Successfully updated document!");
}).catch((error: any) => {
console.error("Error updating document: ", error);
});
}
}
} else {
console.log("No such document!");
}
}).catch(function(error: any) {
console.log("Error getting document:", error);
});
}