Filtering in Realtime Subscriptions

{
    "type": "subscribe",
    "collection": "messages",
    "event": "update"
    "query": { "fields": ["text"] }
}

How to add “owner_id _eq owner1“ filter to the above realtime subscription so directus sends updated messages only to subscribed client with that filter?

1 Answer

1

Hello, @me14523

You can add filters in the query object using the filter key. For example:

{
  "type": "subscribe",
  "collection": "messages",
  "event": "update",
  "query": {
    "fields": ["text"],
    "filter": {
      "owner_id": {
        "_eq": "owner1"
      }
    }
  }
}

Is it missing in the docs? https://directus.io/docs/guides/realtime/subscriptions

Hey, did it work? Please let me know, thanks

You can see the filter queries from here https://directus.io/docs/guides/connect/filter-rules if it works in the there, I think it's worth mentioning the rules page in the docs as well.

Did not work (ignored)!

Try adding the filter in the permissions section that should work.