couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Damien Katz <dam...@apache.org>
Subject Re: sort by key
Date Tue, 22 Sep 2009 16:33:17 GMT
Use a compound key. The first to sort by name, the second by date.  
Then get all the docs in the range of the first key.

function(doc){
     if (doc.user && doc.user.name) {
       emit([doc.user.name, doc.created_time], doc);
   }
}

then
GET /db/_design/users/_view/by_name?start_key=["user  
name"]&end_key=["user name", {}]


On Sep 22, 2009, at 8:59 AM, 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?
>
> Thanks in advance!
>
> Dmitriy Novotochinov
> jabber/googletalk: trybeee@gmail.com
> skype: trybeee
>
>
>


Mime
View raw message