3

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.

1 Answer 1

6

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Upvoted. Is there something like "filter"/"mutator" functions that could be applied when "serializing" to Firebase? That would a useful feature.
@KarolDepka If this answer helped, please accept it instead of upvoting so it can help others as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.