Search code examples
rethinkdbreql

Returning sub attributes in Rethinkdb


Given this document:

{
"Country": {
"ISO-3166-1-Alpha-2":  "AD" ,
"ISO-3166-1-Alpha-3":  "AND" ,
"ISO-3166-1-Numeric": 20 ,
"ISO-3166-2":  "ISO 3166-2:AD" ,
"LongNames": {
"en-us":  "Andorra"
} ,
"ShortNames": {
"en-us":  "Andorra"
} ,
"WebName":  "Andorra"
} ,
"id":  "AD"
}

What would the right query to return just WebName ?

I've tried using Map(), but the results aren't what I expect:

r.db("main").table("countries").limit(1).map(function(r) { return r.WebName; });

RqlDriverError: Anonymous function returned `undefined`. Did you forget a `return`?

Solution

  • In JavaScript, (...) is the field selector.

    r.db("main").table("countries").limit(1)('Country')('WebName')