Search code examples
restcouchbasecouchbase-viewcouchbase-sync-gateway

Couchbase Sync-Gateway View Index Failure


I'm using Couchbase to power the back end of my mobile app and am experiencing a strange error when using views.

I have a view set up to fetch a specific document type and am querying that view via the Sync-Gateway admin API. Normally it works well but I've found that if a document has been recently added to the database then the view query will return 0 results on the first request. The second identical request will then return the expected response.

I suspect that the new document hasn't been indexed by couchbase yet and the query triggers a re-indexing of documents. What I'm wondering is if there's a way of notifying couchbase that I'm about to query the view and to prepare the documents in advance. I don't want to have to perform 2 requests for each query.

Has anyone else come across this issue?

Any solutions?


Solution

  • By default, Sync Gateway allows using a "stale" index, meaning a query won't necessarily rebuild the index before processing a query.

    To override this, add stale=false to your query.

    (Allowed options are false, ok, and update_after. The default is update_after.)