FirestoreProperty: allow ignoring null values
See original GitHub issueI would like to prevent serializing null values when using DocumentReference.SetAsync
to keep documents cleaner and to save storage space. Something like this would be useful:
[FirestoreProperty(nullValueHandling: NullValueHandling.Ignore)]
public string Name { get; set; }
Is there any way to do this currently?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:11 (3 by maintainers)
Top Results From Across the Web
How to exclude a property only if it's null in Firestore?
Is there any possibility to exclude the name property only if it's null? If I pass a real value I want the object...
Read more >Data model
All public instance properties with the FirestoreProperty attribute ... The converter will never be called with a null value from Google.
Read more >Untitled
Ignore undefined properties firestore Reference property from Firestore is always undefined Handling undefined Values with Firebase - Stack Overflow ...
Read more >How can I set firestore to ignore undefined values?
Some of my object fields have undefined values which firestore doesn't accept. I want firestore to ignore these fields and store the rest...
Read more >CRUD With Blazor Using Google Cloud Firestore
This will allow us to map this class object to Firestore collection. Only those class properties, which are marked with [FirestoreProperty] ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
OK. For possible comments from other developers I will present here one real-world sample use case where I have found it useful not to write null values. See this data model (simplified):
For a comparison here is the same class defined in Flutter/Dart where I can omit the null values easily as I want:
Event
contains common data to all events. Depending onEvent.EventType
only one of theRefuel
/Expense
/Service
/Trip
contains event specific data (others must be null).So when I am looking at those documents for example in Firebase console while debugging my app, I wouldn’t like to even see those null values, because they just make reading the documents harder. Also, I don’t know how much those null values take space, but if and when my app has millions of users those unnecessary null values may start to cost me.
Someone could say I should move
Refuel
/Expense
/Service
andTrip
to a different collection and only link them with an id field. I did consider that also but I like this current schema. it is easy to use and also cost effective.@MilosGrgov90: I haven’t heard anything from the Firestore team about this in the last 2 1/2 years, no. I’ll ping them to see if there has been any activity around this in other languages.