couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <>
Subject Re: Summary view for Pie Charting
Date Thu, 20 Sep 2012 09:11:19 GMT
It's this;

function(doc) {
  emit(, null);

and there is no reduce function.

query with ?startkey="today's date minus 30 days encoded in same
format as", and same for 60 and 90.

And remember to ensure that sorts in the right order.
Perhaps emit it as new Date( or in ISO-8601
formatted string.


On 20 September 2012 08:04, Carl Bourne <> wrote:
> Jens,
> Understand!
> So I guess then the only way to do this is using 3 separate queries with startkey, endkey
for each time period? Then assemble the results externally using whatever performed the query?
> Are there any other options?
> Regards,
> Carl
> On 20 Sep 2012, at 01:18, Jens Alfke <> wrote:
>> This isn’t a valid map function, because it’s not purely functional — it uses
external input in the form of the current date/time. So if the map function is run twice on
the same document, it will not always emit the same output. That’s not allowed.
>> In other words, think of what happens if you generate the index now, and then query
it 90 days from now. The information in the index probably won’t be valid because everything
will have expired already, right? But CouchDB has no idea the index is time-sensitive, so
it’s going to return you the old data anyway. You just cannot put time-sensitive data into
a map function.
>> Instead what you should be doing in the map is writing out the expiration times of
the documents. Then at query time you can see how far in the future those are.
>> —Jens

View raw message