Syntax

r.table(tableName) → table
r.db(dbName).table(tableName) → table

Arguments

List of arguments to provide.
tableName
string
required
Name of the table to reference. Must be a valid table name within the selected database.

Optargs

No optional arguments.

Returns

table
object
Returns a query builder table reference that can be used for further operations like querying, inserting, updating, or deleting documents.

Behavior

  • When called without a database context (r.table()), operates on the default database.
  • When called with a database context (r.db().table()), operates on the specified database.
  • The table reference itself doesn’t execute any operations until combined with action methods like run().
  • Returns all documents in the table when executed directly with run().

Notes & Caveats

  • The table must exist before it can be referenced. Use tableCreate to create new tables.
  • Table names are case-sensitive.
  • Table names must follow RuloDB naming conventions (ASCII alphanumeric characters, hyphens, and underscores).

Example

Reference a table in the default database

Get all users from the users table in the default database.
const cursor = await r.table('users').run(client);
const users = await cursor.toArray();

console.table(users);

Reference a table in a specific database

Get all orders from the orders table in the ecommerce database.
const cursor = await r.db('ecommerce').table('orders').run(client);
const orders = await cursor.toArray();

console.table(orders);

Chain operations on a table

Filter and sort users from a specific table.
const cursor = await r
  .table('users')
  .filter((doc) => doc.age.ge(18))
  .orderBy('name')
  .limit(10)
  .run(client);

const adultUsers = await cursor.toArray();

console.table(adultUsers);
  • r - Referencing the query builder
  • db - Referencing a database
  • tableCreate - Creating a table
  • tableDrop - Dropping a table
  • tableList - Listing tables
  • insert - Inserting documents
  • filter - Filtering documents
  • get - Getting a specific document

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