"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?"
Through a list function, you could, but not otherwise. A view is a linear sequence of rows ordered by the full key, couchdb can only efficiently look up a key or return all rows falling between two keys. There's no such thing as a "complex" key in couchdb, it's just that keys can be arrays and couchdb has a declared scheme for ordering of arrays. B. On 26 October 2013 11:06, Andru Vallance <[email protected]> wrote: > 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
