Skip to content Skip to sidebar Skip to footer

Firebase Push Doesn't Add But Replace (JavaScript)

I'm having following code to add remarks ('opm') to a person ('leerling'). function onFormSubmitted() { event.preventDefault(); var ref = new Firebase('https://mydatabase.

Solution 1:

When I passed leerling from a regular input type='text' field it worked fine but when I passed it from a select-option input field it failed as described.

Answer :

var leerlingRef = ref.child("leerling").child(_leerling.substring(0,6).trim()); 

instead of

var leerlingRef = ref.child("leerling").child(_leerling); 

on line 15


Solution 2:

I'd suggest using Firebase.update() as it will either create or update a value. Using Firebase.push() removes any, and all data at a certain sub-tree is removed and replaced with what you sent.

So just replace any reference of Firebase.push() with Firebase.update() and your code should work as expected.

Link for ref: Firebase.update()

Note: This will replace any reference of the data that you are updating. So if you have the value "opmID": 1 in Firebase, updating "opmID" to 2 would replace the original "opmID": 1. As Firebase acts like a dictionary, keys can only exist once.


Post a Comment for "Firebase Push Doesn't Add But Replace (JavaScript)"