如何在 firebase 实时数据库中设置数据值?
How to set value of data in the firebase real time data base?
我尝试刷新数据库中变量的值。但是函数 .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
})
假设您要设置对象 data
,
this.afDatabase.collection("TacoPoint").doc(auth.uid).set(data);
所以我成功使用了.set()
我们只需要像这样对数据库中的对象进行引用:
const a = this.afDatabase.object(`TacoPoint/${data.uid}`) // reference
a.set(/*some data*/) // now you can use the set function
我尝试刷新数据库中变量的值。但是函数 .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
})
假设您要设置对象 data
,
this.afDatabase.collection("TacoPoint").doc(auth.uid).set(data);
所以我成功使用了.set()
我们只需要像这样对数据库中的对象进行引用:
const a = this.afDatabase.object(`TacoPoint/${data.uid}`) // reference
a.set(/*some data*/) // now you can use the set function