为什么Typescript中的集合在firebase中更新了两次



// round page
newRound() {
console.log('new round ', this.round);
this.you.score = +this.score;
this.round++;
console.log('THE PLAYERS -> ', this.players);
this.afStore.collection('matches').doc(this.gameRoom).collection('match').doc(`${this.round}`).set({players: this.players, round: this.round}).then(() => {
console.log('UPDATED GAME');
});
this.router.navigate(['/events/tab2/' + this.gameRoom]);
}
// Tab page that goes to the round page
// NOTE: this is for the next page, round 1,2,3,4 etc...
theRound() {
this.newRound++;
console.log('this is the new round ', this.newRound);
this.afStore.collection('matches').doc(this.gameRoom).collection('match').doc(`${this.newRound}`).set({players: this.players, round: this.newRound});
this.afStore.collection('matches').doc(this.gameRoom).collection('match').doc(`${this.newRound}`).valueChanges().subscribe((v: any) => {
this.router.navigate(['/events/tab2/' + this.gameRoom + '/' + v.round]);
console.log('data returned from firebase ', v);
});
}

大家好!我有个问题。我试图在firebase中更新一个特定的集合,但它会创建集合,但在我在圆形页面中输入值后不会更新"分数"。此外,它还创建了具有更新分数的第二个集合。任何帮助都将不胜感激。

好吧,用set()更新文档,firebase文档显示:

如果文档不存在,则会创建它。如果文档确实存在,则其内容将被新提供的数据覆盖,除非您指定数据应合并到现有文档中

但在更新之前,您对this.newRound进行了增量,因此您的文档的增量更高,firebase会创建一个新文档。

最新更新