couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Hewitt <>
Subject Re: Sorting dates in CouchDB
Date Mon, 08 Oct 2012 09:40:03 GMT
We split our dates into an array of integers, so today's date would look like: 


And we do the same for time, and then combine them in the view function and emit a compound

emit([folder, date], doc._id);

We can then query by:

?startkey=["test", [2012,10]&endkey=["test", [2012,10,{}]

To get all of October's entries in the "test" folder.

If you choose to go down this route (i.e. parsing your date string into a JS Date object in
the view function), just be aware that the Javascript date object uses 0-based months, (January
as month 0 instead of 1).   


On Monday, 8 October 2012 at 10:21, Carl Bourne wrote:

> Hi I just wanted to sanity check what I'm doing here.
> I have a bunch of documents stored in Couch with expiry dates like this: "expire": "2020-07-28T15:13:00+00:00"
> I have a simple map function defined like this:
> function(doc) {
> emit(doc.expire);
> }
> I'm then querying the data ranges like this: ?startkey="2012-10-02"&endkey="2012-12-02"
> Is this the correct way to do this type of thing?
> Regards,
> Carl 

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