Sync Gateway query view update after document delete



Couchbase version: 4.5.1 Community
Sync Gateway version: 1.4.0

We are seeing some odd behaviour around documents still existing in query views after they have been deleted via the sync gateway admin REST API. We have a view as follows:

{"views":{"userprofilebyfacebook":{"map": "function(doc, meta) { if( doc.type && !doc._deleted) { if(doc.type==\"profile\") { emit(doc.facebookID); } } }"}}}

Created via the REST API on startup of the sync gateway application server.

We use this view to detect of a users profile exists on our server when they login/signup using social media. If the view returns a valid document ID, we fetch this document via a couchbase N1QL query (SELECT * FROM sync_gateway where facebookID="some-id") and log the user in to our service. If the view returns no documents, we assume the user does not exist and we create the user profile document via the sync gateway admin API.

If we delete a users profile (our delete blocks until the query view does not return a valid document id, so its gone from the query view) and then re-run the social login, the query view userprofilebyfacebook returns a valid document, but when we try and fetch this document from couchbase via the N1QL query, sometimes no document is found. The document not being found is what we expect, we do not expect it to still exist in the query view, because we blocked the response from the delete call until it stopped returning the document.

NOTE: we are running 2 instances of sync gateway behind a load balancer. Is it possible that 1 sync gateway instance no longer has the document in the view but the other sync gateway instance does? If so, how can we resolve this?


Are you querying the view with stale=false?

If this parameter is not set, then it will return stale results, which might be out of date (aka stale).


No I am not adding that query parameter, I will add that and see how we get on.

Thanks for the reply.