Syntax

sequence.filter(predicate) → sequence

Arguments

List of arguments to provide.
predicate
function
required
A function that takes a document as input and returns a boolean value. Documents for which the predicate returns true will be included in the result.

Optargs

No optional arguments.

Returns

sequence
Cursor
Returns a cursor pointing to the filtered sequence of documents.

Behavior

  • The filter function evaluates the predicate for each document in the sequence.
  • Only documents for which the predicate returns true are included in the result.
  • The original sequence is not modified; a new filtered sequence is returned.
  • If no documents match the predicate, an empty sequence is returned.

Notes & Caveats

  • The predicate function can only have query builder expressions in its body.
  • The predicate function receives a single document parameter.
  • Use field to access specific fields within the document.
  • Complex predicates can be built using logical operators like and, or, and not.

Example

Filter users by age

Filter for users in the users table where the user’s age is greater than or equal to 21.
await r
  .table('users')
  .filter((doc) => doc.age.ge(21))
  .run(client);

Filter with nested fields

Filter for orders where the shipping address country is UAE.
await r
  .table('orders')
  .filter((doc) => doc.field('address.country').eq('UAE'))
  .run(client);

Filter with multiple conditions

Filter for orders where the status is shipped and the value is greater than 100.
await r
  .table('orders')
  .filter((doc) => doc.status.eq('shipped').and(doc.value.gt(100)))
  .run(client);
  • eq - Logical Equality Operation
  • ne - Logical Inequality Operation
  • lt - Logical Less Than Operation
  • le - Logical Less Than or Equal Operation
  • gt - Logical Greater Than Operation
  • ge - Logical Greater Than or Equal Operation
  • and - Logical AND Operation
  • or - Logical OR Operation
  • not - Logical NOT Operation
  • field - Referencing a Field
  • table - Referencing a Table

Found a typo? Or maybe a broken link? RuloDB is open-source, help us fix it!