Geert-Jan
Geert-Jan

Reputation: 18925

What's the functional difference to using 'replace' vs 'update' conflict resolution in RethinkDB

Rethinkdb's insert operation has a couple of modes for conflict resolution when an attempt is made to insert a document that (based on primary key) already exists. i.e.:

Possible values are "error", "replace" or "update". "error": Do not insert the new document and record the conflict as an error. This is the default. "replace": Replace the old document in its entirety with the new one. "update": Update fields of the old document with fields from the new one.

Although I'm clear on the technical difference between 'replace' and 'update' I'm curious to the functional difference (if any) between the two.

For instance, I figured perhaps one of the two didn't result in a event on the changefeed, when the inserted doc is exactly the same as the already existing doc, but this doesn't seem to be the case.

So, what's the functional difference between the two options?

Upvotes: 2

Views: 1039

Answers (1)

neumino
neumino

Reputation: 4353

replace will replace the whole document (and may remove fields), update will just update the fields, and will never delete fields.

If your document is {id: 1, foo: "hello", bar: "world"}

r.table('data').get(1).update({foo: "bonjour"})
// -> {id: 1, foo: "bonjour", bar: "world"}

r.table('data').get(1).replace({id: 1, foo: "bonjour"})
// -> {id: 1, foo: "bonjour"}

Upvotes: 3

Related Questions