Firestore集合组查询流未更新

时间:2019-12-23 09:24:57

标签: flutter google-cloud-firestore

我正在将Flutter与Firebase Firestore一起用于移动应用程序。以下收集组流有效,每次更新任务字段时都会更新。

Firestore.instance
    .collectionGroup('tasks')
    .snapshots()
    .listen((QuerySnapshot tasksSnapshot) {
  print('task change is triggered');
});

当我用'array-contains'查询集合组时,查询有效,但是对任务的更改不会更新流。

Firestore.instance
    .collectionGroup('tasks')
    .where('assignees', arrayContains: userData.id) // new query line
    .snapshots()
    .listen((QuerySnapshot tasksSnapshot) {
  print('task change is triggered');
});

您能否解释这种现象的原因?我该怎么做才能实时获取集合组查询结果?我应该考虑任何索引设置吗?

1 个答案:

答案 0 :(得分:0)

最后找到了正在发生的事情。 Firebase通常会在URL的Firebase“索引”部分中输出一条带有URL的错误消息,以设置必需的Exemptions。但是当我使用collectionGroup().snapshots().listen()时,没有没有错误消息

然后我打电话给collectionGroup().getDocuments()只是为了看看它是否有效,并且出现了免除URL并弹出错误。设置该豁免后,collectionGroup().snapshots().listen()开始重新工作!

我认为此提示对某人有用。