ReQL command: pluck

Command syntax

sequence.pluck([selector1, selector2...]) → stream
array.pluck([selector1, selector2...]) → array
object.pluck([selector1, selector2...]) → object
singleSelection.pluck([selector1, selector2...]) → object

Description

Plucks out one or more attributes from either an object or a sequence of objects (projection).

Example: We just need information about IronMan’s reactor and not the rest of the document.

r.table("marvel").get("IronMan").pluck("reactorState", "reactorPower").run(conn);

Example: For the hero beauty contest we only care about certain qualities.

r.table("marvel").pluck("beauty", "muscleTone", "charm").run(conn);

Example: Pluck can also be used on nested objects.

// JSON equivalent:
//   { "abilities": { "damage": true, "mana_cost": true }, "weapons": true }
r.table("marvel").pluck(
    r.hashMap("abilities",
        r.hashMap("damage", true).with("mana_cost", true))
    .with("weapons", true)
).run(conn);

Example: The nested syntax can quickly become overly verbose, so there’s a shorthand for it.

// JSON equivalent:
//   { "abilities": [ "damage", "mana cost" ] }, "weapons"
r.table("marvel")
 .pluck(r.hashMap("abilities", r.array("damage", "mana_cost")), "weapons")
 .run(conn);

For more information read the nested field documentation.

© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/java/pluck/