Skip to content

Latest commit

 

History

History
65 lines (48 loc) · 1.64 KB

pluck.md

File metadata and controls

65 lines (48 loc) · 1.64 KB
layout api-command
language Java
permalink api/java/pluck/
command pluck
related_commands
without map
without/
map/

Command syntax

{% apibody %} sequence.pluck([selector1, selector2...]) → stream array.pluck([selector1, selector2...]) → array object.pluck([selector1, selector2...]) → object singleSelection.pluck([selector1, selector2...]) → object {% endapibody %}

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.