Attempting to update a Firebase document results in an error message displayed in the console.
Unhandled promise rejection FirebaseError: "Function DocumentReference.update() called with invalid data. Unsupported field value: undefined (found in field name)"
Upon debugging with console.log()
, it was discovered that the editedItem
variable is not recognized inside the update method.
What is the solution to this issue?
data: () => ({
editedIndex: -1,
editedItem: {
id: 1,
name: "SSFS",
description: "XXXX"
},
newItem: {
id: null,
name: null,
description: null
}
}),
save() {
if (this.editedIndex > -1) {
// Update Category
// Object.assign(this.desserts[this.editedIndex], this.editedItem);
db.collection('categories').where('id', '==', this.editedItem.id).get().then( (querySnapshot) => {
querySnapshot.forEach( (doc) => {
doc.ref.update({
name : this.editedItem.name,
description : this.editedItem.description
}).then(() => {
this.$router.push('/categories')
})
})
})
}
}
Error :
Unhandled promise rejection FirebaseError: "Function DocumentReference.update() called with invalid data. Unsupported field value: undefined (found in field name)