incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Moritz Post <moritzp...@gmail.com>
Subject Included docs in 0.11
Date Wed, 21 Apr 2010 13:08:08 GMT
Hi Couch people

Version 0.11 of CouchDB introduced linked documents (other than the
originating document) in Views. But it seems that the included docs can not
be accessed in lists which use the view:

>>>>> snip - Example from couchdb wiki
Linked documentsFor example, if you have the following hierarchically-linked
documents:

[
{ "_id": "11111" },
{ "_id": "22222", "ancestors": ["11111"], "value": "hello" },
{ "_id": "33333", "ancestors": ["22222","11111"], "value": "world" }

]

you can emit the values with the ancestor documents adjacent to them in the
view like this:

function(doc) {
  if (doc.value) {
    emit([doc.value, 0], null);
    if (doc.ancestors) {
      for (var i in doc.ancestors) {
        emit([doc.value, Number(i)+1], {_id: doc.ancestors[i]});
      }

    }
  }
}

The result you get is:

{"total_rows":5,"offset":0,"rows":[
{"id":"22222","key":["hello",0],"value":null,
"doc":{"_id":"22222","_rev":"1-0eee81fecb5aa4f51e285c621271ff02","ancestors":["11111"],"value":"hello"}},
{"id":"22222","key":["hello",1],"value":{"_id":"11111"},
"doc":{"_id":"11111","_rev":"1-967a00dff5e02add41819138abb3284d"}},
{"id":"33333","key":["world",0],"value":null,
"doc":{"_id":"33333","_rev":"1-11e42b44fdb3d3784602eca7c0332a43","ancestors":["22222","11111"],"value":"world"}},
{"id":"33333","key":["world",1],"value":{"_id":"22222"},
"doc":{"_id":"22222","_rev":"1-0eee81fecb5aa4f51e285c621271ff02","ancestors":["11111"],"value":"hello"}},
{"id":"33333","key":["world",2],"value":{"_id":"11111"},
"doc":{"_id":"11111","_rev":"1-967a00dff5e02add41819138abb3284d"}} ]}

<<<<< snip

I would like to use the result of the view in a list, e.g. get
/db/_design/mydesign/_list/mylist/myview?key="foo"&included_docs=true

But the getRow() function of the list only retrieves my {_id, "22222" } as
value and not the referenced document. The list can also not access included
documents from views that reference the original document (emit( doc._id,
null)  and use include_docs=true ).

Other view parameters provided to lists are taken into account (key,
startkey, group and so on) as expected.

Any clarification (or workaround) for accessing included_docs in lists would
be very much appreciated.

Thanks
Moritz

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