From the Firebase note:
For one key path, such as alanisawesome , updateChildren() updates the data only at the first child level, and any data transferred outside the first child level is treated as a setValue() operation. Multi-channel behavior allows you to use longer paths (e.g. alanisawesome/nickname ) without overwriting data. That is why the first example is different from the second example.
I am trying to use one function createOrUpdateData(object) in my code. In the case of an update, it correctly updates the first level child elements, but if I have a nested object, it removes all other properties of this nested object.
Here is the code:
function saveUserDetails(email,object){ var hashedEmail = Utilities.getHashCode(email); var userRef = ref.child(hashedEmail); return $q(function(resolve,reject){ return userRef.update(object, function(error){ if(error){ reject(error); }else{ resolve("Updated successfully!"); } }); }); }
So if I go through:
{ name: 'Rohan Dalvi', externalLinks: { website: 'mywebsite' } }
Then it will remove other properties inside the externalLinks object. Is there a cleaner and easier way to avoid this?
In short, how can I make sure that nested objects are only updated and that the data is not deleted.
source share