How to update a value by java sdk?


#1

I add a new json object. I’m going to just add a value for this new object.

for example:

Result is new add object. I’m going to assign a value to result. How can I update the following record by Java sdk?

{
  "id": "00060eae-3d93-4e1f-a1b3-efd584513bd9",
  "site": "US",
  "creationDate": "2016-08-22T02:52:49-0700",
  "Result": "",
  "Status": "Failed"
}

Look like buckct.update not existing.


#2

It looks like some of your post (code samples) might have been eaten by formatting? Can you try again, please?


#3

repost

I add a new json object. I’m going to just add a value for this new object.

for example:

Result is new add object. I’m going to assign a value to result. How can I update the following record by Java sdk?

{
"id": "00060eae-3d93-4e1f-a1b3-efd584513bd9",
"site": "US",
"creationDate": "2016-08-22T02:52:49-0700",
"Result": "",
"Status": "Failed"
}

Look like buckct.update not existing.


#4

It looks like sub-document updates is what you are looking for. Checkout this blog post:
http://blog.couchbase.com/2016/may/couchbase-server-45s-new-sub-document

Also these documentation section gives more details
http://developer.couchbase.com/documentation/server/current/sdk/subdocument-operations.html


#5

with Couchbase 4.5, subdocument operations are probably the best choice for that usecase as avsej pointed out.

Note that there is an update operation on the Bucket API, it is called replace (but it forces you to retrieve the whole document, mutate it locally then upload it as a whole again for replace).