Reputation: 705
Can anyone think if an elegant way to do update
and replace
in one line?
I want to use the r.row.without
to remove fields and update at the same query.
Something like:
r.db('db').table('table').get('item_id')
.update({ field_a:'value_a'})
.replace(r.row.without(r.args(['field_b'])))`
simply chaining would be nice but this won't work (update returns a change result).
Upvotes: 2
Views: 559
Reputation: 5289
You can also write .update({field_a: 'value_a', field_b: r.literal()})
to change one field and remove another field at the same time.
Upvotes: 3
Reputation: 81
r.db('db').table('table').get('item_id')
.replace(
r.row.merge(
function(doc){
return {field_a: 'newval'}
}
).without('field_b')
)
Should do the trick
Upvotes: 2