ReQL command: bracket

Command syntax

sequence.bracket(attr) → sequence
singleSelection.bracket(attr) → value
object.bracket(attr) → value
array.bracket(index) → value

Description

Get a single field from an object. If called on a sequence, gets that field from every object in the sequence, skipping objects that lack it.

Under most circumstances, you’ll want to use getField (or its shorthand g) or nth rather than bracket. The bracket term may be useful in situations where you are unsure of the data type returned by the term you are calling bracket on.

Example: What was Iron Man’s first appearance in a comic?

r.table("marvel").get("IronMan").bracket("firstAppearance").run(conn);
// more idiomatically:
r.table("marvel").get("IronMan").g("firstAppearance").run(conn);

The bracket command also accepts integer arguments as array offsets, like the nth command.

Example: Get the fourth element in a sequence. (The first element is position 0, so the fourth element is position 3.)

r.expr(r.array(10, 20, 30, 40, 50)).bracket(3).run(conn);
// more idiomatically:
r.expr(r.array(10, 20, 30, 40, 50)).nth(3).run(conn);

40

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