couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andru Vallance <an...@tinymighty.com>
Subject Skipping complex key values in a view function
Date Sat, 26 Oct 2013 10:06:56 GMT
Is there a way to skip a value in a complex key (i.e. an array key) when using startkey and
end key? That is, is there a way to match any value for an item in the array? 

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.  Since these values are all user defined, and it's likely more
properties will be added in the future, I don't think it's viable to use multiple views specific
to each use case.

I'm currently using a single view map emitting multiple rows with null values to allow me
to specify a null value in my startkey/endkey values.

function(doc){
    if(doc.type==='planting'){
        emit([doc.place_id, doc.plant_id, doc.date_created, doc.date_modified], null);
        emit([doc.place_id, null, doc.date_created, doc.date_modified], null);
       emit([null, null, doc.date_created, doc.date_modified], null);
    }
}

Is there a more elegant way I can do this without the multiple row emits?

(note: I'm actually using PouchDB and replicating to CouchDB, so this map query is actually
being run in the browser with PouchDB)

Thanks
Andru Vallance
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message