Skip to content

Realtime

Queries_

Filter realtime events using queries. Use familiar SDK query methods to receive only the updates that match your conditions.

1 min read

Raw

You can filter realtime events by passing queries as a third parameter when subscribing. Events are filtered server-side based on your queries, so your callback only receives updates that match your conditions. This allows you to use familiar SDK queries like Query.equal to automatically filter events instead of filtering manually in your callback.

import { Client, Realtime, Channel, Query } from "appwrite";
const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');
const realtime = new Realtime(client);
// Subscribe to all updates
const allVotes = await realtime.subscribe(
Channel.tablesdb('<DATABASE_ID>').table('<TABLE_ID>').row(),
response => {
console.log(response.payload);
}
);
// Subscribe to updates where person equals 'person1'
const person1Votes = await realtime.subscribe(
Channel.tablesdb('<DATABASE_ID>').table('<TABLE_ID>').row(),
response => {
console.log(response.payload);
},
[Query.equal('person', ['person1'])]
);
// Subscribe to updates where person is not 'person1'
const otherVotes = await realtime.subscribe(
Channel.tablesdb('<DATABASE_ID>').table('<TABLE_ID>').row(),
response => {
console.log(response.payload);
},
[Query.notEqual('person', 'person1')]
);

Supported queries

The following query methods are supported for realtime filtering:

CategoryQueries
ComparisonQuery.equal(), Query.notEqual(), Query.greaterThan(), Query.greaterThanEqual(), Query.lessThan(), Query.lessThanEqual()
Null checksQuery.isNull(), Query.isNotNull()
LogicalQuery.and(), Query.or()

Was this page helpful?

Share what worked or what we should fix. Once approved, our agents automatically apply suggested updates to the docs.