2

I'm running couchbase server 2.0 (dev preview 4) and using .net client library version 1.2.

When I add some document (json) to my database and then in few seconds (less then 10) I try to get this document via GetView through .net client library and it always returns old value on first query. Only on second query it returns actual value.

When I exec same query through REST api, it returns actual value.

Can anyone provide some information about this?

Adam Crossland
  • 14,198
  • 3
  • 44
  • 54
m03geek
  • 2,508
  • 1
  • 21
  • 41

1 Answers1

3

The default behavior of views in Couchbase is to update the index for a view incrementally. It's requesting a view that actually triggers the incremental update. In other words, when you requested the view the first time, you triggered the index to be updated on the server (only new documents need to be indexed). So the new document(s) was indexed by the time you made the second call to GetVew.

In this way, Couchbase views are eventually consistent. If a stale read is not appropriate or tolerable for your situation, you could use the Stale fluent method when you request the view and modify the default behavior.

So to force the view to be updated before getting results:

var view = client.GetView("beers", "by_name").Stale(StaleMode.False);

Some more info is available at http://www.couchbase.com/docs/couchbase-sdk-net-1.2/api-reference-view.html.

-- John

John Zablocki
  • 1,592
  • 9
  • 6
  • I've setted stale mode to false, but it not helped. But it is strange that REST api through browser works well... – m03geek Jul 04 '12 at 06:22