The Sync Gateway GET /{db}/_all_docs API call is taking a long time to resolve

Hi there,

I’m trying to delete all documents referenced by a channel using the Sync Gateway. There is no direct way to delete documents for a channel that I am aware of so the procedure I have been using is to obtain all of the documents using the GET /{db}/_all_docs API call and then calling POST /{db}/_purge on all of the returned documents. This is working properly. The problem is that the GET _all_docs call is taking a really long time. I created a channel with only 6 documents on my local development environment and the GET _all_docs call took ~6 seconds to return.

I tried to look at the query that the Sync Gateway makes to retrieve this data, but the query that’s used is not visible in the Query Monitor in Couchbase Server as per below:

The problem seems to be that the result count for this query is too high which is causing the delay. There are 6 documents that are returned by the _all_docs call from the Sync Gateway. For the query made to Couchbase Server the result count is 37478, but there are ~47000 documents in the bucket which also seems a bit strange.

Is there something I can add to the _all_docs to help it complete faster? Right now I don’t send any parameters in the call.

As always thanks so much for all your help!!

Edited to include versions:
Couchbase Server 6.0.1 Enterprise Edition
Sync-Gateway 2.5.0 Community Edition

Hi @justincheema ,

You can use the _changes endpoint for a more efficient way to retrieve docs by channel, something like:


Details here:

Public REST API | Couchbase Docs