couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carl Bourne <carl.bou...@me.com>
Subject Re: Sorting dates in CouchDB
Date Mon, 08 Oct 2012 13:08:39 GMT
Thanks Aurélien,

I'll try these options to see which is going to work best for me!

On 8 Oct 2012, at 12:53, Aurélien Bénel <aurelien.benel@utt.fr> wrote:

> Hi Carl,
> 
>> OK so if I understand you correctly if I'm only querying using the date part e.g.
"2012-12-02" then it will work OK? 
> 
> I'm not sure to understand, but if you use "key" instead of "startkey" and "endkey",
you will need the exact value you emitted.
> 
> You have indeed several solutions:
> 
> 1. emit the whole timestamp as a string, and query with startkey and endkey using an
endkey that is alphabetically greater than the last key you want to grasp (for example : "2012-12-03"
or even "2012-12-02Z" instead of "2012-12-02") :
> 
> ?startkey="2012-10-02"&endkey="2012-12-03"
> or 
> ?startkey="2012-10-02"&endkey="2012-12-02Z"
> 
> {rows:[
> {"key"="2012-10-02T9:00:00+00:00", ...},
> {"key"="2012-12-01T10:00:00+00:00", ...},
> {"key"="2012-12-02T11:00:00+00:00", ...}
> ]}
> 
> 2. emit as a string the part of the timestamp you want to query on, and use startkey
and endkey more naturally:
> 
> ?startkey="2012-10-02"&endkey="2012-12-02"
> 
> {rows:[
> {"key"="2012-10-02", ...},
> {"key"="2012-12-01", ...},
> {"key"="2012-12-02", ...}
> ]}
> 
> 3. emit the whole timestamp as an array and query a part of it:
> 
> ?startkey=[2012, 10, 2]&endkey=[2012, 12, 2, {}]
> 
> {rows:[
> {"key"=[2012, 10, 2, 9, 0], ...},
> {"key"=[2012, 12, 1, 10, 0], ...},
> {"key"=[2012, 12, 2, 11, 0], ...}
> ]}
> 
> 4. emit the whole timestamp as an array and query a (reduced) group of it:
> 
> ?group_level=3&startkey=[2012, 10, 2]&endkey=[2012, 12, 2]
> 
> {rows:[
> {"key"=[2012, 10, 2], ...},
> {"key"=[2012, 12, 1], ...},
> {"key"=[2012, 12, 2], ...}
> ]}
> 
> 
> There's more than one way to do it. ;)
> 
> 
> Regards,
> 
> Aurélien
> 


Mime
View raw message