I have written a view to return all documents from couchbase but it returns null everytime however when I do var viewCount = view.Count(); the correct number is returned. Why is this happening?

Here is my code:

var view = clientConnection.GetView("GetDocuments", "GetAllDocuments");
                
if(view.CheckExists())
{
     //Returns corrent amount of documents
     var viewCount = view.Count();
     Console.WriteLine(viewCount);
}

//Returns 0 rows
return view;

Here is my views from the web GUI just to make sure I am passing the correct names into the GetView method:

enter image description here

EDIT

After reading the article mentioned in the comment I found this:

The return type of GetView is an enumerable IView, where each enumerated value is an IViewRow. The actual view query isn’t run until you enumerate over the view.

Which is all good and well but it still throws a null reference exception

有帮助吗?

解决方案

Depending upon which version of the .NET client you are using, this may be a bug. That's the bad news. The good news it's fixed, but not released (yet):

This will be released the first week of May (version 1.3.5). The bug was introduced in the 1.3.3 release.

其他提示

I'm assuming you are using C# here, if not then it's early and I'm sleepy!

You need to loop over your results, so to print out all your ids or add them to an array etc, you'd have to do this:

foreach (var doc in view)
{
    Console.WriteLine(doc.id);
    //Add id to array or other processing
}

You can see the view documentation for c# here http://docs.couchbase.com/couchbase-sdk-net-1.3/#working-with-views

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top