1

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?

Rob Sanders
  • 5,197
  • 3
  • 31
  • 58
  • What versions of Sync Gateway and Couchbase Server are you running? How are you creating the new document? – Hod Mar 08 '18 at 05:04
  • Sync-Gateway is 1.5.1-community. Couchbase Server is latest so 5.1. New document is created from a custom API that uses the admin API over port 4985 – Rob Sanders Mar 08 '18 at 16:15

1 Answers1

2

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.)

Hod
  • 2,236
  • 1
  • 14
  • 22