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
将仅更新字段,而不会删除字段。
如果您的文档是 {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 - 在 RethinkDB 中使用 'replace' 与 'update' 冲突解决有什么功能差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29102418/