Syntax

object.pluck(key1, key2, ..., keyN) → object
object.pluck([key1, key2, ..., keyN], {optargs}) → object

sequence.pluck(key1, key2, ..., keyN) → cursor
sequence.pluck([key1, key2, ..., keyN], {optargs}) → cursor

Arguments

List of field selectors to pluck from the documents.
key
string
required
Name of the field(s) to reference. Use dot notation to reference nested fields.

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

result
object | Cursor
For single objects, returns an object containing only the specified fields. For sequences, returns a cursor pointing to the projected sequence of documents.

Behavior

  • Plucks out only the specified fields from each document, creating a projection.
  • If a specified field doesn’t exist in a document, it’s omitted from the result.
  • When the primary key (id) is not included in the projected fields, the cursor cannot be iterated over for updates.

Notes & Caveats

  • The original documents are not modified; new documents are returned.

Example

Pluck specific fields from a user

Get only the id, name and email fields from a user document.
const user = await r.table('users').get('user_123').pluck('id', 'name', 'email').run(client);

Pluck fields from multiple documents

Get only the id, title and author fields from all blog posts.
const posts = await r.table('posts').pluck('id', 'title', 'author').run(client);

Pluck nested fields

Get nested address information from user documents.
const users = await r
  .table('users')
  .pluck('id', 'name', 'address.city', 'address.country')
  .run(client);
  • get - Get a document by primary key
  • getAll - Get multiple documents
  • filter - Filter documents
  • field - Reference a specific field
  • update - Update documents
  • insert - Insert new documents
  • without - Remove fields from documents

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