firestore: Checking if structure is empty #11425
Labels
api: firestore
Issues related to the Firestore API.
type: bug
Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Is your feature request related to a problem? Please describe.
The data model I am trying to write in firestore contains some nested structures. Like this:
For our business logic is alright if the user do not provide address so in this case the Address object is empty(containing only zero-value fields) and I want to omit it. This tag "omitempty" is not working in this case. The result in firestore is like that:
Describe the solution you'd like
I would want if I said that nested structure should be omitted when empty then this data is skipped in the firestore document:
I figured out this function is responsible for checking if field is empty or not. Adding one addition case for a struct as simple as that fixes my problem:
Is there specific reason why this is missed in first place? I could not find any information why I cannot say "omitempty" on nested struct?
Describe alternatives you've considered
Changing the nested structure type to be a reference to this object works with "omitempty" but I have to change the code base and introduce a reference when is not needed. Other approach I think of is adding the tag "omitempty" on the fields of the nested structures:
Then this result in the firestore document as empty map:
The text was updated successfully, but these errors were encountered: