Skip to content

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

Open
@civicBoy13

Description

@civicBoy13

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions