[英]run a primitive mycouch query
I'm new to couchdb and mycouch. 我是不熟悉长沙发和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. 我正在尝试实现一个非常简单的查询,我只想获取视图的结果并将其保存到我的DTO类中。
My couchdb query works, when I query it manually via HTTP: 当我通过HTTP手动查询时,我的ouchdb查询有效:
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. 但是,当我尝试使用mycouch从我的应用程序运行它时,我无法运行它。 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. 由于某种原因,它将找不到Client
类。 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. 我发现了一个在github上使用Client
的示例,如您所见,我正在使用与示例中所有MyCouch
相关的名称空间。
I also tried using MyCouchStore
instead: 我还尝试使用MyCouchStore
代替:
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
. 但是, store
不包含任何名为Views
属性。 Any ideas how to query my view using MyCouch? 有什么想法如何使用MyCouch查询我的视图吗?
This is what I do, with the MyCouchStore 这就是我使用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. 构造函数现在需要2个参数,第二个是可选的引导程序。 This worked for me: 这为我工作:
var client = new Client("http://localhost:5984/samples", null)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.