Is it possible to pass the field to be updated withing firestore as a variable?
I want to create an a function to update a document such as...
updateFirebaseDocument('enquiries', 'asdaasdasds, 'status', '1'))
with the following function
export async function updateFirebaseDocument(collectionName, documentId, field, updateValue) {
var doc = db.collection(collectionName).doc(documentId)
return doc.update({
field: updateValue
})
.then(function() {
console.log("Document successfully updated!");
})
.catch(function(error) {
// The document probably doesn't exist.
console.error("Error updating document: ", error);
});
}
Which does work, but the issue is, that it creates a field called field, rather then updating the status field. Is there a way of doing this rather then hard-coding the update fields?