[英]Why is the collection in Typescript update twice in 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 創建了一個新的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.