couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Kirchgessner <martin.ki...@gmail.com>
Subject Re: Views, lookup by a key, then sort by another one?
Date Thu, 06 Jan 2011 14:48:17 GMT
On Thu, Jan 6, 2011 at 3:26 PM, He Shiming <heshiming@gmail.com> wrote:

> Thanks Martin. I actually read those. The key can be a JSON array.
> However, in my situation I only wanted to sort by the date, I didn't
> really want to specify a date in the first type query. Do you have an
> example of what this complex key should look like when querying?
>

To sort by date you should emit( [doc.user_group, doc.updated_at], doc.type)
- however documents will still be sorted by user group first.

With such keys you query a perticular date range by providing, for instance,
startkey=["developers",2011-01-04]&endkey=["developers",2011-02-04]
(url-encoded)

You will still be able to do simple queries like : key=["developers"]

If you need to filter documents with updated_at only, another view where
updated_at is the single key is a better option.


HTH,

Martin

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message