angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.68k stars 2.19k forks source link

DocumentChangeAction types are all "added" when a new document is added #2863

Open civicBoy13 opened 3 years ago

civicBoy13 commented 3 years ago

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 { try {
this.firestore .collection('Customers') .add(JSON.parse(JSON.stringify(customer))); } catch (error) { throw error; } }


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.

civicBoy13 commented 3 years ago

Anyone have an answer ??