0

Using branch update logic in rethinkdb. I am needing to update a value based on wether another value matches and then set the appropriate value. If the values are the same it should use the existing value.

r.db('testdb').table('great_table').get(1).update(source => {
  return r.branch(source('some_other_id').eq(1), {read: false}, /* use existing value */);
})

Tried the following:

r.db('testdb').table('great_table').get(1).update(source => {
  return r.branch(source('some_other_id').eq(1), {read: false}, source('checked'));
})

The error I received when I tried this is:

{
  "deleted": 0 ,
  "errors": 1 ,
  "first_error":  "Inserted value must be an OBJECT (got BOOL): false" ,
  "inserted": 0 ,
  "replaced": 0 ,
  "skipped": 0 ,
  "unchanged": 0
}
ckross01
  • 1,681
  • 2
  • 17
  • 26

1 Answers1

1

In your query you are trying to pass bool where Rethink expecting object.

So, your query should look like this (depends in which field you want save source('checked') value):

r.db('testdb').table('great_table').get(1).update(source => {
  return r.branch(source('some_other_id').eq(1), {read: false}, {read: source('checked')});
})