Access StringDocument via a View (Java SDK)

I have a StringDocument which looks like this:
{"_id":“abc”,“type”:“xyz”,“name”:“ABC”,“lat”:42.256943, “features”:“qwwertyuio”}
I know this looks like a JsonDocument but I am upgrading from Java SDK 1.4.4 to 2.3.2 and would prefer to use a StringDocument for minimum changes. In the bucket as this document, there a million other documents. The primary use of this view is to return me a set of documents with “type”: “xyz”.
function (doc, meta)
{
if( doc.type == “xyz” )
{
emit(doc._id);
}
}
Then I iterate over the documents with the id and get the info I need. The problem that I am facing is that it throws a “com.couchbase.client.java.error.TranscodingException: Flags (0x4000000) indicate non-JSON document for id abc” which obviously is because it is a StringDocument. Is there a way around for the same or can I use a different method to query over documents?

Hi @anuja.khemka,

You can use LegacyDocument (http://docs.couchbase.com/sdk-api/couchbase-java-client-2.3.3/com/couchbase/client/java/document/LegacyDocument.html) to retrieve documents stored using 1.x client.

Thank for your reply @subhashni . I found a way to specify the kind of “documents” to retrieve in the ViewQuery (using ViewQuery.includeDocs(StringDocument.class)) and then access it using StringDocument doc = viewRow.document(StringDocument.class)
Even LegacyDocument worked but I wanted to not use it :slight_smile: