Search code examples
rethinkdb

Move object values from objec to array in RethinkDB


I cannot figure out how to convert objects into a JsonArray.

r.db('data').table('user').filter({'_deleted':false}).pluck(['id'])

My result looks like this:

{
   "id":  "10008590"
}, 
{
   "id":  "10006821"
}

And i want it to look like this:

[ "10008590", "10006821"]

what do i add to a query after .pluck()?


Solution

  • Simple, after the pluck() you use the map() function to extract the id field:

    .map(function(doc){return doc('id')})
    

    in shorter form:

    .map(r.row('id'))
    

    Note: in the UI i also needed .coerceTo("array") to the end