incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nils Breunese <n.breun...@vpro.nl>
Subject Re: sort by key
Date Tue, 22 Sep 2009 15:46:44 GMT
Dmitriy Novotochinov wrote:

> Hello everybody!
> 
> Please help me to implement sorting by key.
> 
> Here is view function:
> 
> function(doc){
>       if (doc.user && doc.user.name) {
>         emit(doc.user.name, doc);
>     }
> }
> 
> Query all docs where user.name = user_name:
> 
> /_design/users/_view/by_name?key=user_name
> 
> Query returns docs sorted by key doc.user.name, but how to do sorting  
> by doc.created_at, for example?

Results from a CouchDB view are always sorted by key (you can only 
specify ascending or descending).

You either have create a different view or you actually want your 
sorting to be based on the *values*. I haven't tested it, but the 
CouchDB Footrest extension provides this feature: 
http://github.com/assembly/couchdb-footrest (see 'Order Docs By Value 
Fields')

Nils.

Mime
View raw message