rethinkdb - 在 RethinkDB 中使用 'replace' 与 'update' 冲突解决有什么功能差异

标签 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 将仅更新字段,而不会删除字段。

如果您的文档是 {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/

相关文章:

rethinkdb - 如何在 RethinkDB 中进行 'getNearest' 地理空间查询?

performance - RethinkDB 更改提要性能 : architectural advice?

rethinkdb - RethinkDB 中服务器生成的 UUID 有什么优势吗?

javascript - Rethinkdb 通过一个查询和条件进行多次更新

ubuntu - 如何在 Ubuntu 上卸载 RethinkDB?

node.js - ExpressJS 和 RethinkDb 教程无法读取未定义的属性 'prototype'

json - 如何使用 JavaScript 在 ReThinkDB 中的 ReQL 中对数组应用过滤器

rethinkdb - rethinkdb 适合聊天应用吗

Angular 2 : removeAll() in RethinkDB with Horizon API

python - 在 rethinkdb 中插入 python datetime 的最佳方法是什么?