Does Index Streaming work this way?


I have been working on index streaming. I have an index like this.

  name: "CheckNotification",
  unique: false,
  serialized: true,
  source: "Notification",
  terms: [
      field: ["data", "isRead"]

I want to show unread notifications to the users. I have created a query whose isRead value is false.

 final stream = faunaClient.setStream(Match(Index("CheckNotification"), terms: [false]), {});

When I create a document in the Notification Collection, I can get event streaming. There is no problem here.
But If I delete this document and create a new one, I’ll get the deleted document as well.

flutter: {"title":"Notif. 1","isRead":false}
flutter: -------------------
flutter: {"title":"Notif. 1","isRead":false} -- This one was deleted
flutter: {"title":"Notif. 2","isRead":false}
flutter: -------------------

Why am I getting deleted documents? Is this normal?

Hi @hasimyerlikaya, yes this is normal.

The Index contains the Set of all Documents that match the terms provided. When you delete a Document, it must be removed from the Index.

In this case, I have to check every document because I can’t be sure if it’s deleted or not. I would expect to get only the available documents somehow.

Thank you.

Every event contains the action that triggered the event. For Set (Index) streams, the possible actions are add and remove. You can read about streaming events in our documentation here: Event streaming - Fauna Documentation

You may still need to do something to differentiate between remove because the document was updated or because it was deleted.

I would expect that, but here is the problem:
When I delete a document, the stream is not working. I don’t know if this problem is caused by the Dart package that I’m using. I can only handle creating events.
When streams work after creation, stream data contains deleted documents as well.