How to atomically replace a document if it does not exist in Rethinkdb> = 1.11

I updated rethinkdb to 1.11.2 and found backward incompatibility in the update / replace commands. In 1.10, both commands return the correct answer

r.db('test').table('user').get("notFound").update({a: 1}) // {"skipped": 1 ,...}
r.db('test').table('user').get("notFound2").replace({a: r.row('a').default(0).add(1)}) // {"inserted": 1 ,...}

but in 1.11.2 an error with an error:

RqlRuntimeError: Expected type OBJECT but found NULL. in:
r.db("test").table("user").get("notFound").update({a: 1})

I want to update a simple document using an atomic single request (without checking if it exists).

Is there a way to execute the in request in rethinkdb> = 1.11 along path 1.10?

+4
source share
2 answers

, : https://github.com/rethinkdb/rethinkdb/issues/209, Runtime , . :

r.do(r.db('test').table('log').get('3333'), function(x) {
  return r.branch(
    x.eq(null),
    r.db('test').table('log').insert({id: '3333', log: 'looool', c: 1}),
    r.db('test').table('log').get('3333').update(function(l) { return {c: l('c').add(1)}; })
  )
});

, , , , .

EDIT: 1.11.1 1.11.3, . :

r.db('test').table('log').get('3333').replace(function(x) {
  return r.branch(
    x.eq(null),
    {id: '3333', log: 'haiii', c: 1},
    x.merge({c: x('c').add(1)})
  )
})
+4

, ( replace), upsert. . upsert http://rethinkdb.com/api/javascript/insert/.

UPDATE: , upsert update, . replace, , , insert.

0

All Articles