在 RethinkDB 中使用 'replace' 与 'update' 冲突解决的功能区别是什么
What's the functional difference to using 'replace' vs 'update' conflict resolution in RethinkDB
Rethinkdb 的 insert
操作在尝试插入(基于主键)已经存在的文档时有两种解决冲突的模式。即:
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.
虽然我很清楚 'replace' 和 'update' 之间的技术差异,但我对两者之间的功能差异(如果有的话)感到好奇。
例如,当插入的文档与现有文档完全相同时,我想也许两者之一不会导致更改源上的事件,但事实似乎并非如此.
那么,这两个选项在功能上有什么区别?
replace
将替换整个文档(并可能删除字段),update
只会更新字段,而不会删除字段。
如果您的文档是{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"}
Rethinkdb 的 insert
操作在尝试插入(基于主键)已经存在的文档时有两种解决冲突的模式。即:
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.
虽然我很清楚 'replace' 和 'update' 之间的技术差异,但我对两者之间的功能差异(如果有的话)感到好奇。
例如,当插入的文档与现有文档完全相同时,我想也许两者之一不会导致更改源上的事件,但事实似乎并非如此.
那么,这两个选项在功能上有什么区别?
replace
将替换整个文档(并可能删除字段),update
只会更新字段,而不会删除字段。
如果您的文档是{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"}