My Firestore document has a field with a value already set.
Now I want to remove the value by setting it to something that signifies "empty" such as null
or undefined
.
So far I have tried doing this with the updateDoc
method like so:
updateDoc(documentReference,{ photoURL: undefined })
But it throws this error:
Function updateDoc() called with invalid data. Unsupported field value: undefined (found in field photoURL in document users/d23xxxxxxxxxxxxxxx12)
And setting it to null
is also not allowed because if I try to set it to null
like so:
updateDoc(documentReference,{ photoURL: null })
TypeScript will throw this error:
Type 'null' is not assignable to type 'FieldValue | Partial | undefined'.
I found that using an empty string like updateDoc(documentReference,{ photoURL: "" })
works but it's not as elegant as null
or undefined
.
I will use the empty string if no other solutions are found, but perhaps there is another way?