incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Markus Burrer ...@embedit.de>
Subject Re: get by property
Date Fri, 23 Sep 2011 13:42:18 GMT
Am 23.09.2011 14:10, schrieb Nils Breunese:
> You could create views for every property you want to be able to use as a lookup key
(by_flash, by_ram, by_eeprom, by_package) and emit the property value as the key: emit(property_value,
null); Then you can query the view for the property you're looking for, e.g /db/_design/ddoc/_view/by_flash?key="8kbyte"
>
> Or you could create a single view which indexes all properties with their values by emitting
the property key and value as a complex key: emit([property_key, property_value], null); Then
you can query the view like this: /db/_design/ddoc/_view/all_properties?key=["Flash","8kbyte"]
Hi Nils,
thanks. I prefer the second version. My map function now looks like 
this. Is this correct?

function(doc) {

   if(doc.record_type=="article"){

     for(var key in doc.properties){

       emit([key, doc.properties[key]], doc._id);

     }

   }

}


The query /test/_design/find/_view/by_property?key=["Flash","8kByte"] 
returns the result

{"total_rows":8,"offset":3,"rows":[
{"id":"ATmega8A-PU","key":["Flash","8kByte"],"value":"ATmega8A-PU"}
]}

Looks good for me.

Mime
View raw message