0

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()?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I am having trouble finding examples / documentation online. Do you happen to know where using map in this context is documented? None of the rethinkdb official docs show how things are outputted in their examples.
True, the official docu doesnt mention this exact use case and do not bother providing sample outputs. But rethinkdb provides the web UI which makes the experiencing pretty quick and easy, i usually do that. Your use case can be achieved with map, concatMap, and do, you can find some examples and ideas there in the official documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.