View Results Include Various Revisions of Documents?

Are views supposed to return multiple revisions of a document? I wrote a simple view

function(doc) { if(doc.centerId && doc.type == ‘DailyReport’) { emit([doc.centerId, doc.reportDate], null)}}

and I’m finding that the results (when retrieved either through the web console or through the java sdk) include way more documents/rows than I expected. Upon looking at the results closer, I’m seeing that they include all of the various revisions of some documents. Older revisions all have an id with a format like “_sync:rev:documentNameXYZ:34:1-0d84ffd32e88ed8c966214bdab872c4f” while the current document just has an id like “documentNameXYZ”. Is this expected behavior? Or is there a way to get the view to only return current documents/revisions?"

Thanks,
Bill

Hi @Foosh,
From the attributes returned I see that you are using Sync Gateway for parts of your application:

And then you are using the Java SDK to query the Sync Gateway bucket for documents, is that correct?

If you save documents using Sync Gateway, we recommend that you also use Sync Gateway for the retrieval.
Sync Gateway is a synchronisation/broker and needs to keep track of version and revisions on all documents, therefore when you query the sync gateway bucket “raw” it will return all revision and versions that is being tracked.
Using Sync Gateway for the query would filter this to only relevant revsions and documents.

I hope this helps
Martin

Hi @martinesmann,

Thanks for the response! You are right that we are using the Sync Gateway. We have a mobile app that uses Couchbase Lite and uses the Sync Gateway to replicate data to Couchbase Server. We previously replicated to CouchDb but we’re currently looking into switching to Couchbase Server. We also have a web app that uses the Java SDK to query and interact with Couchbase Server. We previously used Ektorp and Jackson to work with CouchDb.

I didn’t think we could just swap the CouchDb url for the Sync Gateway end point in our web app but if that’s possible, it would make the transition extremely easy. Does the Sync Gateway provide the same support as the CouchDb REST Api? We need the ability to perform standard CRUD operations as well as query views we’ve set up on Couchbase Server.

Thanks,
Bill