Client.GetView(designName, viewName) returns nothing


Hello there,

I am stuck by not getting back any view from the following code:

var view = client.GetView(“test”, “byStyle”);

The cluster.RetrieveDesignDocument returns by the below code are:

{“views”:{“byCategory”:{“map”:“function (doc, meta) {\n emit(, null)
”},“byStyle”:{“map”:“function (doc, meta) {\n emit(, null);\n}”}}}

CouchbaseCluster cluster = new CouchbaseCluster(config);
var ret = cluster.RetrieveDesignDocument(“default”, “test”);

I can’t figure out why client.GetView(“test”, “byStyle”) returns 0 row.

Can somebody please help?

Thanks a ton!


Does the view work in the Web UI?

Also, you can add a debug parameter and that will have it add additional logging information in the cluster node’s log directory.


Thanks for the reply.

Yes, the view works in the web UI.

Can you elaborate on how to add a debug parameter?


Hi lindatang1998 -

I assume you are referring to view.TotalRows? If so, it’s a deferred operation so you must enumerate over it before it’s actually executed:

var view = client.GetView("test", "byStyle"); Assert.AreEqual(view.TotalRows, 0); //will return true

//now we iterate over the enumeration
foreach(var x in view){
//do something

Assert.Greater(0, TotalRows); //will return true assuming we have data

Another way to do this is by using the Count() method:

var view = client.GetView("test", "byStyle"); var count = view.Count(); Assert.Greater(0, count); //will return true if data is available

If that is not the problem, in the Couchbase Server Console, make sure that the view is published to production.



Hi Jeff,

Thanks for the explanation. You are correct about both TotalRows and Count().