On Oct 26, 2013, at 3:06 AM, Andru Vallance <[email protected]> wrote:

> I have a document with a place_id, plant_id, date_created and date_modified. 
> Sometimes I want all docs with place_id=X and plant_id=Y, where other times I 
> only want place_id=X and any plant_id; sometimes I will want to specify a 
> creation and/or modification date, other times this will not be relevant.

This should work with a single emit, unless I’m misunderstanding you. The trick 
is to use an empty object — {} — as a placeholder for the end of a range, since 
it will sort after any scalar or array value.

>From your example:
>        emit([doc.place_id, doc.plant_id, doc.date_created, 
> doc.date_modified], null);

To query for all docs with place_id=X and plant_id=Y, use
        startkey = [place_id, plant_id]
        endkey = [place_id, plant_id, {}]
To query for place_id=X and any plant_id, use
        startkey = [place_id]
        endkey = [place_id, {}]

—Jens

Reply via email to