问题描述
我将二进制数据放在 Couchbase 中。但是对于我的新用例,我需要设置一个名为 created_date 的字段以及我的文档。我正在考虑为此使用 xattr。
此字段“created_date”的目的是将其用于同一文档的两个版本之间的比较(假设为 doc_1)
例如
doc_1 - created_date1 - 目前在沙发上
doc_1 - created_date2 - 从上游接收
我需要比较 created_date2 与 created_date1 并仅在 created_date2 > created_date1 时替换 Couchbase 中的上游文档。
我正在为 Couchbase 使用 Java SDK。我在 Couchbase 中使用 upsert 进行插入/更新,它支持 UpsertOptions 中非 JSON 文档的转码器。
UpsertOptions upsertOptions = UpsertOptions.upsertOptions()
.transcoder(transcoder)
但是对于设置 Xattr 我想我必须使用
collection.mutateIn
因为 MutateInSpec 支持 xattr
MutateInSpec.replace("created_date",created_date).xattr())
但是我找不到在
中指定转码器的选项MutateInoptions.mutateInoptions()
任何帮助将不胜感激。
解决方法
所以你需要在写xattr的同时写二进制文档体?这是可能的,你可以这样做:
collection.mutateIn("doc-id",Arrays.asList(
// Make sure xattrs go first in the specs list
MutateInSpec.upsert("xattr-path","xattr-field").xattr(),// You can replace the document's body with binary data like this
MutateInSpec.replace("",new byte[]{1,2,3,4})));