首页 > 解决方案 > 如何在firebase实时数据库中设置数据值?

问题描述

我尝试刷新数据库中变量的值。但是.set()函数需要两个参数,我不明白第一个是什么。

我尝试使用该.push()功能,但这会在我的数据库中创建一个新行。我不想要那个。我想要改变价值。

所以我知道我需要使用该.set()函数,但她需要两个参数项:Firebase 操作和数据

第一个是什么?

    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 

        })

标签: angularfirebase-realtime-databaseangularfire2

解决方案


假设您要设置 object data

this.afDatabase.collection("TacoPoint").doc(auth.uid).set(data);

推荐阅读