You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by João Ramos <jo...@gmail.com> on 2012/07/02 23:12:42 UTC

Map/reduce problem

Hi,

I have a map function that emits these keys:
    [doc.type, 2012, 2, 14]
    [doc.type, 2012, 2, 14]
    [doc.type, 2012, 4, 22]
    [doc.type, 2012, 5, 23]

This works great because I can get exactly what I want (ajusting the
group_level accordingly): for each doc type, how many exist each day, or
each month, each year or just by doc type.

Now my problem is that I also want to filter by date, for example: between
two dates, for each doc type, how many exist for each day, month or year?
Since startkey / endkey cannot have empty keys on the left (in order to
ignore the doc type and just filter by date), how can I do this?

If my keys where in the form of [2012, 2, 14, doc.type], I would be able to
filter properly by date, but then, for each day, I would have to manually
accumulate for each doc type (and the list has several years).

Is what I'm asking even possible?
Thank you.

Re: Map/reduce problem

Posted by Mark Hahn <ma...@hahnca.com>.
I personally store dates by standard ms number and take the trouble to
figure out the startkey and endkey.  Standard date functions can easily let
you pick a particular year, mon, day, or any other range.

On Mon, Jul 2, 2012 at 2:12 PM, João Ramos <jo...@gmail.com> wrote :

> Hi,
>
> I have a map function that emits these keys:
>     [doc.type, 2012, 2, 14]
>     [doc.type, 2012, 2, 14]
>     [doc.type, 2012, 4, 22]
>     [doc.type, 2012, 5, 23]
>
> This works great because I can get exactly what I want (ajusting the
> group_level accordingly): for each doc type, how many exist each day, or
> each month, each year or just by doc type.
>
> Now my problem is that I also want to filter by date, for example: between
> two dates, for each doc type, how many exist for each day, month or year?
> Since startkey / endkey cannot have empty keys on the left (in order to
> ignore the doc type and just filter by date), how can I do this?
>
> If my keys where in the form of [2012, 2, 14, doc.type], I would be able to
> filter properly by date, but then, for each day, I would have to manually
> accumulate for each doc type (and the list has several years).
>
> Is what I'm asking even possible?
> Thank you.
>

Re: Map/reduce problem

Posted by Matthieu Rakotojaona <ma...@gmail.com>.
On Mon, Jul 2, 2012 at 11:12 PM, João Ramos <jo...@gmail.com> wrote:
> Now my problem is that I also want to filter by date, for example

You actually want 2 unrelated ways of querying your data; the only
thing I can see is that you use 2 different views, one for each of
your query.


-- 
Matthieu RAKOTOJAONA