couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sean Copenhaver <sean.copenha...@gmail.com>
Subject Re: get by property
Date Fri, 23 Sep 2011 14:12:33 GMT
Just a nitpick really, but you don't need to emit any value if you are only
interested in the _id or retrieving the full document.

As you can see in the results you lists the document's id is already given
and you can specify the query string parameter "include_docs=true" to fetch
the full doc with your results.

I thought I would add that in case you were unaware.

On Fri, Sep 23, 2011 at 9:42 AM, Markus Burrer <mb@embedit.de> wrote:

> 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.
>



-- 
“The limits of language are the limits of one's world. “ - Ludwig von
Wittgenstein

"Water is fluid, soft and yielding. But water will wear away rock, which is
rigid and cannot yield. As a rule, whatever is fluid, soft and yielding will
overcome whatever is rigid and hard. This is another paradox: what is soft
is strong." - Lao-Tzu

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