Search code examples
angularfirebase-realtime-databaseangularfire2

How to set value of data in the firebase real time data base?


I try to refresh the value of a variable in my data base. But the fonctions .set() need two arguments and I don't understand what is the fisrt.

I try to use the .push() fonction but this create a new line in my data base. I d'ont want that. I want the value change.

So I know i need to use the .set() function but she take two arguments item: Firebase operation and data

What is the first ?

    this.afAuth.authState.subscribe(data => { // ajoute des tacoPoint 
          this.test = this.afDatabase.list(`TacoPoint/${data.uid}`).valueChanges();

          this.test.forEach(data => { // ajoute des tacoPoint 
            data.forEach(e => {


              e.Tacopoint = e.Tacopoint + 20;
              console.log(e);

            })
          })
        })

        this.afAuth.authState.subscribe(auth => {
         this.afDatabase.list(`TacoPoint/${auth.uid}`).set(); // need to set the new TacoPoint in the data base 

        })

Solution

  • So I succeeded to use the .set() We just need to do a reference at the object in the data base like that :

    const a = this.afDatabase.object(`TacoPoint/${data.uid}`) // reference 
    
    a.set(/*some data*/) // now you can use the set function