You can use replace
with a branch and an explicit merge.
replace
is like update
, except it completely replaces a document rather than merging with it. The following are equivalent (in Ruby code):
table.get(id).update{|row| {a: row['a']+1}}
table.get(id).replace{|row| row.merge({a: row['a']+1})}
So if you want to do an "update", or else insert a row if there is no row, you could do this:
table.get(id).replace {|row|
r.branch(
row.eq(nil),
INSERT_OBJECT,
row.merge(UPDATE_OBJECT))
}