To filter results based on conditions, you can use the where method. This method accepts a list of clauses as arguments. A clause is a tuple that takes the form [attribute, operator, value].

For example the following query will return all registered users.

const query = client
  .select(['id', 'name', 'email', 'dob'])
  .where('is_registered', '=', true);

Clauses can be passed to where as a single clause or an array of clauses:

  • .where('is_registered', '=', true)
  • .where(['is_registered', '=', true])
  • .where([['is_registered', '=', true]])

If multiple clauses are provided, all clauses are joined with a logical AND. However, you may use or and and methods within the clause array to specify how clauses should be logically grouped and joined.

For example the following query will return all registered users who are either an admin or an owner.

import { or } from '@triplit/client';
const query = client
  .select(['id', 'name', 'email', 'dob'])
      ['is_registered', '=', true],
        ['role', '=', 'admin'],
        ['role', '=', 'owner'],

You may use dot notation to filter by attributes of a record.

const query = client.query('users').where('', '=', 'New York');

If you define relationships in your schema you may also access those via dot notation. Triplit will autocomplete up to 3 levels of depth, but arbitrary depth is supported.

const query = client
  .where('', '=', 'Dr. Smith');


See the list of data types for more information on the operators that can be used in a where clause.

Id shorthand

If you want to query by the entity's ID, you can use the id method as a shorthand for where('id', '=', id). E.g.

const query = client.query('users').id('the-user-id');