How can I get document content with couchbase java-client 3.x? Something like bucket.defaultCollection().get(row.id().get(), getOptions().transcoder(RawJsonTranscoder.INSTANCE).timeout(Duration.ofSeconds(10))).contentAs(String.class);
in the foreach can work but isn’t the right way.
i.e.
ViewResult viewResult = bucket.viewQuery(“design-doc-name”, “view-name”);
for (ViewRow row : viewResult.rows()) {
System.out.println("Found row: " + row);
…row.document()…
}
Hi David, not sure why but in my case doesn;t work.
With couchbaseClient in SDK 1.x I had a list of ViewRowWithDocs that have following fields(id, key, value, doc).
I SDK 3.x I had a list of ViewChunckRow that have only (id, key, value).
Id, key and value are the same but doc is something else and I don’t know ho to get it, except getting each document.
In the SDK3 for ViewRow.valueAs(JsonObject.class), I’ve got Deserialization of content into target class com.couchbase.client.java.json.JsonObject failed; encoded = {"from":98254059}. But its content is not I’m expected.
In SDK 1, I get this too for value field, but "doc " looks totally different. Now I can get that value using bucket.defaultCollection().get(row.id().get(), getOptions().transcoder(RawJsonTranscoder.INSTANCE).timeout(Duration.ofSeconds(10))).contentAs(String.class);
which is not the right way to do it, doing a read for each document id.
Document content is something like
{“id”:“f147174a-46eb-4aa8-90ed-e2a6dce264c3”,“amount”:20.0,“src”:“MAIN”,"“created”:“210115171323595+0000”,“changed”:“210115171323595+0000”,“transactions”:[{“step”:1,“orderId”:98254059},{“step”:2,“orderId”:98254059}]}
valueAs() return View result (what javascript “function (doc, meta) {emit(…)})” returns) and I need the whole document. the document content was included in the response in previous SDK versions. Now, how can I can get it and not calling get foreach row?
Thanks for clarifying the issue. I asked around and learned that the “include docs” feature was not carried forward from SDK 2 to SDK 3; as a result, it’s necessary to fetch the document content in a separate request. I realize this probably isn’t the answer you were hoping for. As I understand it, the motivation for this change was to simplify the View API, and to give users more flexibility in how they want to load the documents.