Thanks,
So I'm assuming the only way to to summarise this information is to do 3
separate queries and aggregate the results?
> It's this;
>
> map:
> function(doc) {
> emit(doc.date.expire, null);
> }
If I query against the above without a reduce (_count) function it returns all
documents according to the ?startkey="2012-10-19" and not the count which I
need to build the pie chart!
Am I understanding you correctly?
Carl
On 20 Sep 2012, at 10:11, Robert Newson <[email protected]> wrote:
> It's this;
>
> map:
> function(doc) {
> emit(doc.date.expire, null);
> }
>
> and there is no reduce function.
>
> query with ?startkey="today's date minus 30 days encoded in same
> format as doc.date.expire", and same for 60 and 90.
>
> And remember to ensure that doc.date.expire sorts in the right order.
> Perhaps emit it as new Date(doc.date.expire).getTime() or in ISO-8601
> formatted string.
>
> B.
>
>
> On 20 September 2012 08:04, Carl Bourne <[email protected]> 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 <[email protected]> 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
>>