The following code guarantees that any given document will be saved in a durable manner to the active node in a Couchbase cluster, as well as replicated to 1 additional node:

cas, err := myBucket.UpsertDura(docToStore, valueToStore, 1, 1)

Given that Couchbase Views are eventually consistent, it would seem that I have 2 options in terms of guaranteeing consistency when invoking a view after writing a document (ensuring that the document appears in the view):

Option 1

Change the replicateTo value in the above code to equal the total number of additional nodes (minus the active node) in the cluster, ensuring that each node contains a copy of the document:

cas, err := myBucket.UpsertDura(docToStore, valueToStore, 3, 4)

Option 2

Use the standard Upsert function to save the document, but invoke the View with stale-mode set to after-update

_, err := bucket.Upsert(myID, &myDoc, 0)

vq := gocb.NewViewQuery("doc", "view").Stale(gocb.StaleMode(1))
err = bucket.ExecuteViewQuery(vq)

Are there any alternatives to achieve this in the most performant manner possible? Essentially I would like for the document the appear in all relative views immediately after saving.


,您需要将陈旧模式设置为false。 如果设置了stale = ok,则即使视图已过时,Couchbase也不会刷新视图。 这样做的好处是改善了查询延迟。 如果设置了stale = update_after,则Couchbase将在返回过时的结果后更新视图。 如果设置了stale = false,则Couchbase将刷新视图并返回最新的结果。 </ p>
</ div>



you need to set the stale mode to false. If stale=ok is set, Couchbase will not refresh the view even if it is stale. The benefit of this is a an improved query latency. If stale=update_after is set, Couchbase will update the view after the stale result is returned. If stale=false is set, Couchbase will refresh the view and return you most updated results.

douci4026 我想我正在打破Go的基本规则-试图变得太聪明。 调用视图时,我会将stale-mode设置为false。
4 年多之前 回复