nipunasudha
nipunasudha

Reputation: 2617

Firestore collection group query stream is not updated

I'm using Flutter with Firebase Firestore for a mobile app. The following collection group stream works and is updated every time a task field is updated.

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

When I query the collection group with 'array-contains', the query works but a change to a task doesn't update the stream.

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

Could you explain the reason for this behavior? And what should I do to get collection group query results in real-time? Are there any indexing settings I should consider?

Upvotes: 4

Views: 1630

Answers (1)

nipunasudha
nipunasudha

Reputation: 2617

Finally found what was going on. Firebase usually outputs an error message with a URL to set required Exemptions in Firebase 'Indexes' section. But there was no error message when I was using collectionGroup().snapshots().listen().

Then I called collectionGroup().getDocuments() just to see if it's working and an error popped up with an exemption URL. After setting that exemption, collectionGroup().snapshots().listen() started to work again!

I thought this tip would be useful for someone.

Upvotes: 7

Related Questions