简体   繁体   中英

run a primitive mycouch query

I'm new to couchdb and mycouch. I'm trying to implement a very simple query, I just want to get the results of a view and save it into my DTO class.

My couchdb query works, when I query it manually via HTTP:

http://localhost:5984/mydb/_design/tshirts/_view/getAllTshirts

However, when I try running it from my app using mycouch, I can't get to run it. My current query:

using MyCouch.Requests;
using MyCouch.Responses;

// (...)

using (var client = new Client("http://localhost:5984/samples")) {
    var query = new QueryViewRequest("getAllTshirts");

    ViewQueryResponse<TShirt[]> result = await client.Views.QueryAsync<TShirt[]>(query);
    Console.WriteLine (result);
}

For some reason, it won't find the Client class. I found an example where Client is used on github , as you can see, I'm using all the MyCouch related namespaces as in the example.

I also tried using MyCouchStore instead:

using (var store = new MyCouchStore("http://localhost:5984/", "samples")) {
    var query = new QueryViewRequest("getAllTshirts");
    ViewQueryResponse<TShirt[]> result = await store.Views.QueryAsync<TShirt[]>(query);
    Console.WriteLine (result);
}

However, the store doesn't contain any property named Views . Any ideas how to query my view using MyCouch?

This is what I do, with the MyCouchStore

using (var store = new MyCouchStore("http://user:password@localhost:5984", "samples")) {
    var query = new Query("tshirts", "getAllTshirts");

    var rows = store.QueryAsync<TShirt>(query).Result;
}

Apparantely, the documentation was not up to date. The constructor requires now 2 arguments, the second being an optional bootstrapper. This worked for me:

var client = new Client("http://localhost:5984/samples", null)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM