Firestore snapshotChanges DocumentChangeType “已删除"从未发送 [英] Firestore snapshotChanges DocumentChangeType "removed" never sent

查看:22
本文介绍了Firestore snapshotChanges DocumentChangeType “已删除"从未发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 where 子句查询 Firestore 集合,并订阅了 snapshotChanges.根据文档,我应该为每个添加、修改和删除的元素获取一个事件.

I'm querying a Firestore collection using a where clause and am subscribed on snapshotChanges. According to the documentation I should get an event for each elements that are added, modified and removed.

添加和修改的文档我都很好,但我从来没有删除过的文档.

I get the added and modified documents fine but I never get the removed ones.

这是我的代码示例:

this.db
      .collection<Test>('test', ref => ref.where('someid', '==', someid))
      .snapshotChanges()
      .subscribe(async snapshot => {
        for (const element of snapshot) {
          switch (element.type) {
            case 'added':
              // Works fine
              break;
            case 'modified':
              // Works fine
              break;
            case 'removed':
              // Never triggered
              break;
          }
        }
      });

我假设这是因为我使用的是 where.有没有人遇到过这种情况?

I'm assuming it's because of the fact i'm using a where. Has anyone encountered this?

更新:2020-10-14

经过更多测试,似乎只有 AngularFirestore 有问题,Firestore 本身没有问题.同时,作为一种解决方法,我直接使用 AngularFirestore.firestore.onSnapshot.

After more testing, it appears to be an issue only with AngularFirestore and not Firestore itself. In the meantime as a workaround I use AngularFirestore.firestore.onSnapshot directly.

更新:2020-11-04事实证明,对于 AngularFirestore,您需要使用 stateChanges 来获得我正在寻找的行为.希望这可以帮助某人.

UPDATE: 2020-11-04 Turns out with AngularFirestore you need to use stateChanges to get the behavior I was looking for. Hope this can help someone.

推荐答案

事实证明,使用 AngularFirestore 时,您需要使用 stateChanges 来获得我想要的行为.

Turns out with AngularFirestore you need to use stateChanges to get the behavior I was looking for.

以下文档解释了 snapshotChanges 和 stateChanges 之间的区别:https://github.com/angular/angularfire/blob/master/docs/firestore/collections.md

Here's the documentation that explains the difference between snapshotChanges and stateChanges: https://github.com/angular/angularfire/blob/master/docs/firestore/collections.md

这篇关于Firestore snapshotChanges DocumentChangeType “已删除"从未发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆