I am trying to enter workout information into a Firebase Realtime database from a vue js web app. However, it overwrites data when I try to insert into it. If I enter information for bicep curls and then enter bicep curls again instead of appending it overwrites the original. For example, I want it to be setup like this:
users
This is my way of inserting data:
writeUserData: function() {
const db = getDatabase();
var data = {
'weight': this.weight,
'reps': this.reps,
'sets': this.sets,
'date': Date(),
}
userRef = ref(db, 'users/', this.name, this.workoutType);
set(userRef, [data]);
},
Every time you call set with a reference, it replaces any existing data at that ref.
If you want to create a new unique child nodes under the ref, use push instead of set.
push(userRef, data)
Also see the Firebase documentation on appending to a list of data.
Using an array notation like you're trying won't work unless you first read the existing data from the location. Trying to do this is an antipattern in Firebase though, so I also recommend reading Best Practices: Arrays in Firebase.