0

How can I order results from a couchdb database, using cradle for node.js? From the docs it seems that adding a descending=true parameter to my url should work. My current code is as follows:

this.db.view('articles/all',function(error, result) {

    if( error ){
        callback(error)
    }else{
        var docs = [];
        result.forEach(function (row){
            docs.push(row);
        });
        callback(null, docs);
    }

});

The articles are ordered by date (as set in my view below)

function (doc) { 
    if (doc.created_at) emit(doc.created_at, doc);
}

If I change the first line to

this.db.view('articles/all?descending=true',function(error, result) {

no results are returned

So, how can I order results in cradle for couchdb?

Thanks!

4

1 に答える 1

0

これが正しい CouchDB パラメータです。ゆりかごのコードを見ると、パラメーターをクエリ パス (最初の引数) の一部として渡しているとは思えません。クレードルがクエリ文字列を取得してめちゃくちゃにしていると思います。実際に生成されているリクエスト文字列を確認できますか? 関数は、オプションである別の引数を取る可能性があるようです。だから多分それは次のようなものです:

this.db.view('articles/all',{descending: true},function(error, result) {

それがあなたに近づくことを願っています。申し訳ありませんが、私はそのライブラリを使用したことがなく、私の JavaScript はそれほど優れたものではありません。

Marcello Nuccio さんの質問のコメントが表示されませんでした。彼は最初に答えを指摘したと思います。

于 2011-04-22T20:53:17.137 に答える