Angular 更新firestore数据后显示重复事件,但firestore中的数据本身不是';不重复

Angular 更新firestore数据后显示重复事件,但firestore中的数据本身不是';不重复,angular,firebase,ionic3,google-cloud-firestore,angularfire2,Angular,Firebase,Ionic3,Google Cloud Firestore,Angularfire2,我有一个web应用程序(Angular)和一个移动应用程序(Ionic)。两者共享相同的Firestore数据 使用web应用程序更新现有数据,但ionic应用程序显示重复项(重复项将在重新启动移动应用程序后消失),我在Firestore中检查项目数据本身,它已更新且唯一。有人对此有任何线索吗 此问题仅出现在除web应用程序以外的移动应用程序上,它们都使用“angularfire2”:“^5.0.0-rc.4”, 做了研究,似乎(不是100%确定)是一个有角度的问题: 由于重新启动后副本消失,

我有一个web应用程序(Angular)和一个移动应用程序(Ionic)。两者共享相同的Firestore数据

使用web应用程序更新现有数据,但ionic应用程序显示重复项(重复项将在重新启动移动应用程序后消失),我在Firestore中检查项目数据本身,它已更新且唯一。有人对此有任何线索吗

此问题仅出现在除web应用程序以外的移动应用程序上,它们都使用
“angularfire2”:“^5.0.0-rc.4”,

做了研究,似乎(不是100%确定)是一个有角度的问题:


由于重新启动后副本消失,其他人也报告了此问题,我觉得问题出在
AngularFirestore
本身。作为解决方法,您可以尝试以下方法:

 import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';

   this.posts$ = this.db.getRecentPosts().snapshotChanges().pipe(
      map(arr => arr.reduce((acc, doc) => { // map -> reduce
        const id = doc.payload.doc.id
        // remove !(id in acc) to get last duplicate
        !(id in acc) && acc[id] = { id, ...doc.payload.doc.data() } 
        return acc }
        }, {} // reduce seed
      )),
      // you can also Object.values(arr.reduce(...)), but this I find bit more readable
      map(coll => Object.values(coll))
    );

谢谢你的回复。目前,我自己删除重复项。我真的很想知道什么是避免这个问题的最佳解决方案。你找到这个了吗??每次我更新某些内容时,它都会在前端重复。这好像是用别的方法处理的不?我想你应该检查一下你是否忘记退订了。
 import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';

   this.posts$ = this.db.getRecentPosts().snapshotChanges().pipe(
      map(arr => arr.reduce((acc, doc) => { // map -> reduce
        const id = doc.payload.doc.id
        // remove !(id in acc) to get last duplicate
        !(id in acc) && acc[id] = { id, ...doc.payload.doc.data() } 
        return acc }
        }, {} // reduce seed
      )),
      // you can also Object.values(arr.reduce(...)), but this I find bit more readable
      map(coll => Object.values(coll))
    );