I have a class which I'm saving to Firebase using update().
Is it possible to prevent certain fields (known by name) of the object being saved, from being saved to firebase db?
Think like transient in java.
I mean without using JS delete operator.
When you call update(), Firebase will change the value of each property (or path) that you've specific in the object you pass in. If you don't want a specific property to be used, don't pass it in.
If you have an existing object and you want a copy that excludes a few fields:
Or:
var obj = { a: 1, b: 2, c: 3, d: 4, e: { f: 5 } }
var updates = {};
Object.keys(obj).forEach((key) => {
if (key !== "c") updates[key] = obj[key];
});
ref.update(updates);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With