Firebase Web Update() Deletes All Other Child Nodes
Solution 1:
What is actually happening in your code is the folowing:
You are writing entirely to the key thereby wiping off the whole properties in your dataset.
this
updates2['/offer/' + keyReal] = offer;
wipes out the whole data in that particular key.
Try this instead:
firebase.database().ref('offer/' + keyReal).update({
minusAccandShare: 2,
});
this allows you to make sure you change the specified property in your firebase dataset.
I hope this helped
Solution 2:
Seems like you should read up on firebase refs. You don't seem to be updating the ref so you're updating (presumably) the root DB object (I have never passed a blank ref to Firebase so I'm not 100% sure what the behavior is of using firebase.database().ref()
.
I've "compiled" your code so you we can see what you're passing to the empty ref:
var updates2 = {};
updates2['/offerLight/' + keyReal] = offer;
updates2['/offer/' + keyReal] = offer;
// Becomes...
updates2 = {
'/offerLight/jifdjsiavdas': {
minusAccandShare: 2
},
'/offer/jifdjsiavdas': {
minusAccandShare: 2
}
}
// So...return firebase.database().ref().update( updates2 );
// is sent asreturn firebase.database().ref().update({
'/offerLight/jifdjsiavdas': {
minusAccandShare: 2
},
'/offer/jifdjsiavdas': {
minusAccandShare: 2
}
})
It seems like what you actually want to be doing is referencing the child node jifdjsiavdas
. You'll want to point to it with a reference like this:
firebase.database.ref( 'offer/' + keyReal ).update( offer );
Post a Comment for "Firebase Web Update() Deletes All Other Child Nodes"