[Bug] Collection not updating properly on document deletes
I am subscribed to a collection using the async pipe, however when I go to delete a document inside the collection, any object below the deleted document gets removed from the UX and the collection observable isn't updated.
When I delete from the firebase database console, it works as intended
Thanks!
Do you use .limit()? Or query more than once to the same path? It might be the similar to what happens to me https://github.com/angular/angularfire2/issues/1356
No i'm not using any queries/limits. Just pulling the collection and calling snapshotChanges() to get the document ids with the docs.
I believe we are having the same issue. For me to force the update, I just call the collection again.
@muffinrecon Can you use the issue template and create a stackblitz? That will be much easier to debug.
Any update on this? I am having the same issue. When a document is deleted, a new value is emitted within the snapshotChanges() subscription. Only, the DocumentChangeAction[] is empty. There is no 'removed' action.
Hmmm... I'll take a peek here. If someone can put a repro together on stackblitz it would be appreciated.
Is this Firestore or RTDB?
I think is the same bug than this one https://github.com/angular/angularfire2/issues/1356, there are 2 stackblitzs
^ I think it is a different bug. I switched over to stateChanges, and I now receive 'removed' events. It seems like snapshotChanges does not provide 'remove' events.
Closing this one as due to lack of information and inactivity.
@jkossis snapshotChanges emits the state of your collection, so it will not emit a "removed" event. Only the array without the item removed. stateChanges seems like what you want since it is the stream of events as they occur.
Hi @davideast, @jamesdaniels. Could you help me please ? i think i have a similar issue... I get different results when I delete a few objects. Do I have to get the same result?
Could you check the link below ? Stackblitz link
this.afs.collection('items', ref => ref.orderBy('date', 'desc'))
.snapshotChanges().map(actions => {
return actions.map(action => {
const data = action.payload.doc.data();
const _id = action.payload.doc.id;
return {_id,...data};
});
});
this.afs.collection('items', ref => ref.orderBy('date', 'desc')).valueChanges();
results image:

@YamanSehzade Did you manage to resolve this issue? I am facing almost exactly the same.
@Luke-Rogers Unfortunately, no
@YamanSehzade, @Luke-Rogers In the future try not to respond to closed posts, just open a new bug so we'll see it. It get a lot of notifications from Github so I don't always see responses to closed issues.
For your case your problem was that you were creating multiple observables and subscribing them to the view. This is because you created your Observables with functions rather than properties. Each time you click "load items" or even run change detection, you're creating a new observable which will cause race conditions in the view.
In general you should treat your observables are properties instead of functions. They are a stream of updating content, you don't need to call a function to create one to unwrap more data. Just create the observable as a property, tack on your operators, and subscribe.
See the forked version I created for a fix: https://stackblitz.com/edit/firebase-delete-issue-enpcws?file=app%2Fhome.component.ts
@davideast Unfortunately your fork does not seem to fix the issue. For example, if you add until around 5 items are in the list, then start deleting them, you will see that sometimes, two are removed from the UI until you refresh.
Happy to open this as a new issue if necessary.
I noticed the same thing. For example in my app I have enablePersistence set to true and if I delete a document in the firebase console, that document is still in the cache and get loaded whenever I checked for snapshotChanges