Syntax

table.get(key) → document

Arguments

List of arguments to provide.
key
string
required
The primary key value of the document to retrieve.

Optargs

No optional arguments.

Returns

document
object | null
Returns the document object if found, or null if no document exists with the specified key.

Behavior

  • Retrieves exactly one document based on the primary key.
  • Returns null if no document is found with the specified key.
  • The operation uses the table’s primary key index for optimal performance.

Notes & Caveats

  • RuloDB uses id as the primary key field.

Example

Get a user by ID

Retrieve a specific user by their ID from the users table.
const user = await r.table('users').get('user_123').run(client);

if (user) {
  console.log('Found user:', user.name);
} else {
  console.log('User not found');
}

Get a document from a specific database

Retrieve an order from the orders table in the ecommerce database.
const order = await r.db('ecommerce').table('orders').get('order_456').run(client);
  • getAll - Get multiple documents by primary keys
  • filter - Filter documents by conditions
  • table - Reference a table
  • insert - Insert documents
  • update - Update documents
  • delete - Delete documents

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