create a new Child with the same name instead of overwriting-firebase

Asked

Viewed 44 times

0

I need help on firebase i have a code that creates a "Child" (I think that’s what it’s called) called "Records" inside the node(folder/table) called "users" that takes a value passed by parameter, but whenever this function is called and this code is executed I would like instead of always overwriting Child "Records" would like to be created another one with the same name(Records) with the value passed, ie whenever calling the function create a Child, my code is like this:

      async setRecord(recordPoints){
      const uid = firebase.auth().currentUser.uid
      return await firebase.database().ref('usuarios').child(uid).child('records').set({
        record: recordPoints
      })
  }

thanks in advance :)

1 answer

0


In this example you need to use the push in place of set, as stated in the documentation:

Add to a list of data in the database. Every time you push a new Node onto a list, your database generates a Unique key, like messages/users//

https://firebase.google.com/docs/database/admin/save-data

In your case, it would be something like

async setRecord(recordPoints){
      const uid = firebase.auth().currentUser.uid
      return await firebase.database().ref('usuarios').child(uid).child('records').push({
        record: recordPoints
      })
  }
  • Thanks bro, it worked here, if it’s fucking!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.