DocumentChangeAction types are all "added" when a new document is added
When i add a new document to firestore and listen for the snapshot changed, every documentchangeaction that is returned has "added" as type, as opposed to the just the newly added document.
Version info
Angular: ~11.2.0
Firebase: ^7.0 || ^8.0
AngularFire: ^6.1.5
Other (e.g. Ionic/Cordova, Node, browser, operating system): ionic: 6.13.1
How to reproduce these conditions
Some samples of my code
this is inside of my firbease service
customerCollectionsAddedListener(){ try { return this.firestore.collection("Customers").snapshotChanges(); } catch (error) { throw error; } }
async createCustomerDocument(customer: Customer): Promise
this.firestore
.collection
this.firebase.customerCollectionsAddedListener().subscribe(value => { value.forEach(action =>{ var payload = action.payload; console.log(action.type); console.log(payload.type) ; if(action.type === "added" && payload.doc.metadata.fromCache){ console.log(payload.doc.id); console.log(payload.doc.data()); } }); });
Debug output
Expected behavior
The expected behavior is that only the newly added document has the type of added.
Actual behavior
The actual behavior is that all the documents have a type of added.
Anyone have an answer ??
This is expected Firestore behavior rather than a bug: when you subscribe to snapshotChanges(), the initial emission delivers every existing document in the collection as an 'added' change, and only later inserts arrive individually as 'added' while edits arrive as 'modified'. So seeing all documents as 'added' on the first snapshot is correct.
I'm closing this as working as intended; if you see something different on a current @angular/fire release, please comment and we can revisit.