Question

Is there any way to update a sequence and know the primary keys of the updated documents?

table.filter({some:"value"}).update({something:"else"})

Then know the primary keys of the records that were updated without needing a second query?

Was it helpful?

Solution

It's currently not possible to return multiple values with {returnVals: true}, see for example https://github.com/rethinkdb/rethinkdb/issues/1382

There's is however a way to trick the system with forEach

r.db('test').table('test').filter({some: "value"}).forEach(function(doc) {
  return r.db('test').table('test').get(doc('id')).update({something: "else"}, {returnVals: true}).do(function(result) {
    return {generated_keys: [result("new_val")]}
  })
})("generated_keys")

While it works, it's really really hack-ish. Hopefully with array limits, returnVals will soon be available for range writes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top