To access a specific field in each document of a sequence, use doc.field(), which retrieves that field’s value from every document in the result set.

Syntax

object.fieldNamevalue
object.field(name, {optargs}) → value

Arguments

List of arguments to provide.
name | fieldName
string
required
Name of the field to reference. Use dot notation to reference nested fields. To reference non-nested fields, use the field’s name as a reference (see in the examples).

Optargs

Optional arguments to customize the behavior of the function. Provided as an object.
separator
string
default:"."
Separator to use when referencing nested fields

Returns

value
any
Returns the value of the referenced field. The type of the value depends on the contents of that field in each document.

Behavior

  • The object.field() function is aware of the table’s schema if defined.

Notes & Caveats

  • Whenever a field name contains a dot (.), provide a custom separator using the separator option to avoid unexpected behavior.

Example

Filter users that are older than 21

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

Filter orders from the UAE

Filter for orders in the orders table where the order’s shipping address country is UAE, where the country is a nested field of address.
await r
  .db()
  .table('orders')
  .filter((doc) => doc.field('address.country').eq('UAE'))
  .run(client);

Filter for usernames

Filter for users in the users table where the user’s property.username (literal field name) is john. In this example, we use the separator option to specify a custom separator for nested fields.
await r
  .db()
  .table('orders')
  .filter((doc) => doc.field('property.username', { separator: ',' }).eq('john'))
  .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
  • table - Referencing a Table
  • filter - Filtering Documents

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