Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
The `getField` command works on sequences in RethinkDB 1.7

The getField command now works on sequences

In the previous versions of RethinkDB you could get a subset of an object using the pluck command, and the value of a specific field using the getField command (accessible via () in Javascript and [] in Python and Ruby):

r.expr({a: 1, b: 1}).pluck('a')
// returns {a: 1}

r.expr({a: 1, b: 1})('a')
// returns 1

You could also run the pluck command on sequences of objects, like arrays and tables. However, running getField on sequences didn't work directly, so you had to use map:

r.expr([{a: 1, b: 1},
        {a: 2, b: 2}]).pluck('a')
// returns [{a: 1}, {a: 2}]

r.expr([{a: 1, b: 1},
        {a: 2, b: 2}])('a')
// returned an error

r.expr([{a: 1, b: 1},
        {a: 2, b: 2}]).map(r.row('a'))
// returns [1, 2]

As of the 1.7 release you can run getField on sequences as well as objects directly, and use the name getField if you prefer:

r.expr([{a: 1, b: 1},
        {a: 2, b: 2}])('a')
// now returns [1, 2]

r.expr([{a: 1, b: 1},
        {a: 2, b: 2}]).getField('a')
// now returns [1, 2]

See more about the 1.7 release in the release announcement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment