Couchbase .Net Client Query Generation
Hello,
I have a question about the http request that couchbase .net client makes to satisfy my query.
I have one bucket with one view on the couchbase server. The map function on the view is :
function (doc) { if(doc.type=='Article'){ emit(doc._id, doc);} }
In my test, i am using the couchbase client like this:
public void Test_get_by_title()
{
var client = new CouchbaseClient();
var query = client.GetView("content", "articles")
.Select(a => (string) a.GetItem())
.Select(x => JsonUtility.Deserialize<Article>(x))
.Where(art => art.Title == "clp test");
foreach (var article in query)
{
Console.WriteLine(article.Id);
}
}JsonUtility.Deserialize is a static method which uses NewtonsoftJson.Net for deserialization.
Now this does what I want, but not in the way I thought.
I was under the assumption that the http request to the couchbase server would include the condition as a query string. And the http response will bring back only the Article JSON which meet this condition.
But the request that is being sent is http://11.1.1.111:8088/bucket_name/_design/dev_content/_view/view_name without any query string and this brings back everything from couchbase and then deserializes all the rows and then filters the list of Articles.
As you can see this behavior is not acceptable when we have large data.
Please help me in the right direction, What am I doing wrong?
I am using Couchbase .Net Client 0.9.2 and the server is version 2.0.0 community edition (build-388-gf35126e).
All help is appreciated.
I noticed the same thing and it makes the performance horrible...there is no way this could be used in a production environment. The original Hammock API for CouchDb had the Linq code emitting the view and then executed the proper request on that view:
var r = new Repository(s);
var z = r.Where(x => x.Name).Eq("PS3")
.And(x => x.Price).Le(400)
.List();
Hammock will update CouchDB's design document with a new view:
{
"_id": "_design/product",
"language": "javascript",
"views": {
"by-name-price": {
"map": "
function(doc) {
if (doc._id.indexOf('product-') === 0) {
emit([doc.Name, doc.Price], null);
}
}",
"reduce": null
}
}
}
And then execute a request against that view, using the parameters specified:
GET /sample-db/_design/product/_view/by-name-cost?startkey=["PS3",null]&endkey=["PS3",400]
http://code.google.com/p/relax-net/
IMO, the .NET Couchbase client is completely broken...