我正在使用 where 子句查询 Firestore 集合,并订阅 snapshotChanges。根据文档,我应该为添加、修改和删除的每个元素获取一个事件。
我很好地得到了添加和修改的文档,但我从未得到删除的文档。
这是我的代码的示例:
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.有人遇到过这种情况吗?
更新:2020-10-14
经过更多测试后,这似乎只是 AngularFirestore 的问题,而不是 Firestore 本身的问题。与此同时,作为一种解决方法,我直接使用 AngularFirestore.firestore.onSnapshot 。
更新:2020-11-04事实证明,对于 AngularFirestore,您需要使用 stateChanges 来获得我正在寻找的行为。希望这可以帮助别人。
事实证明,对于 AngularFirestore,您需要使用 stateChanges 来获得我正在寻找的行为。
以下文档解释了 snapshotChanges 和 stateChanges 之间的区别:https://github.com/angular/angularfire/blob/master/docs/firestore/collections.md https://github.com/angular/angularfire/blob/master/docs/firestore/collections.md
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)