You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Moritz Post <mo...@gmail.com> on 2010/04/21 15:08:08 UTC

Included docs in 0.11

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

Re: Included docs in 0.11

Posted by J Chris Anderson <jc...@gmail.com>.
On Apr 21, 2010, at 6:08 AM, Moritz Post wrote:

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

I want to be sure this isn't a basic typo. I think you mean include_docs=true (not included...) I'm pretty sure this works.

> 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