Skip to content

Commit 568c499

Browse files
committed
JSCBC-1369: MutateIn Replace with empty path should do a full doc replace
Motivation ---------- The RFC states that on a mutateIn Replace with an empty spec, the SDK should d oa full doc replace Changes ------- Change the opcode to a SET_DOC when an empty path is provided onto a replace mutateIn spec Change-Id: Id862f3fa7e64a72ff2d69122bdbbdafe7a278809 Reviewed-on: https://review.couchbase.org/c/couchnode/+/234798 Reviewed-by: Jared Casey <jared.casey@couchbase.com> Tested-by: Mateusz <matt.wozakowski@couchbase.com>
1 parent 0925b1c commit 568c499

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/sdspecs.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,14 @@ export class MutateInSpec {
408408
value: any | MutateInMacro,
409409
options?: { xattr?: boolean }
410410
): MutateInSpec {
411-
return this._create(
412-
binding.protocol_subdoc_opcode.replace,
413-
path,
414-
value,
415-
options
416-
)
411+
let opCode = binding.protocol_subdoc_opcode.replace
412+
413+
// On an empty path we replace the whole document
414+
if (path.length === 0) {
415+
opCode = binding.protocol_subdoc_opcode.set_doc
416+
}
417+
418+
return this._create(opCode, path, value, options)
417419
}
418420

419421
/**

0 commit comments

Comments
 (0)