簡體   English   中英

運行原始的mycouch查詢

[英]run a primitive mycouch query

我是不熟悉長沙發和mycouch的人。 我正在嘗試實現一個非常簡單的查詢,我只想獲取視圖的結果並將其保存到我的DTO類中。

當我通過HTTP手動查詢時,我的ouchdb查詢有效:

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

但是,當我嘗試使用mycouch從我的應用程序運行它時,我無法運行它。 我當前的查詢:

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);
}

由於某種原因,它將找不到Client類。 我發現了一個在github上使用Client的示例,如您所見,我正在使用與示例中所有MyCouch相關的名稱空間。

我還嘗試使用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);
}

但是, store不包含任何名為Views屬性。 有什么想法如何使用MyCouch查詢我的視圖嗎?

這就是我使用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;
}

顯然,該文檔不是最新的。 構造函數現在需要2個參數,第二個是可選的引導程序。 這為我工作:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM