Android Firebase update only some fields

The reference with which you are performing the update is for the path FB_REFERENCE_USER - which appears to be the path which contains the users.

updateChildren updates only the immediate children, with the values under those being replaced. So the update is replacing the entire child for the user and is leaving the children for the other users untouched. That is the expected behaviour.

You need to perform the update using a ref for that specific user - so that the properties of that user that are not being updated are left untouched.

That is, you need to do something like this:

User user = new User(userID, userName, userMail, userActive);
Map<String, Object> postValues = user.toMap();
myRef.child(userID).updateChildren(postValues);

The behaviour of updateChildren is described here in the documentation.


Yes, you can update the single node without loss of other existing data.

You need to create a pojo and set the values which you want to update in the existing node and send that pojo object to setValue(pojo) method.

For example:

User updatedUser=new User();
updatedUser.setName("Rishabh");
updatedUser.SetEmail("[email protected]");
myref.setValue(updatedUser);

PS: myref is the reference up to the user id node in which you want to update the data.


if you want to update only some field, try to use

myRef.child(userID).child("which field do you want to update").setValue(ValueVariable);