You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Ladislav Prskavec <la...@prskavec.net> on 2011/05/30 16:35:18 UTC

Problems with array with include_docs

Hello,
i have problem with my views. View 1 work's fine, geting parent document by _id, but in View 2 by include_docs=true not get parent document requested by '_id': XXX.

# View 1

function(doc) {
for (var idx in doc.studyList) {
 if (doc.studyList[idx].focusId!="" && doc.studyList[idx].focusId!=null) { 
var pole = doc.studyList[idx].focusId.split(/[ -]+/);
for (var i=0; i<pole.length;i++) {
emit([pole[i], doc.parentId], {'_id': doc.parentId});
}
 }
}
}


_design/fields/_view/focusIdtest?include_docs=true

{"id":"7L000","key":["1002",0],"value":{"_id":0},"doc":null},
{"id":"13430","key":["1002","13000"],"value":{"_id":"13000"},"doc":{"_id":"13000","_rev" ...


# View 2

function(doc) {
for (var idx in doc.studyList) {
 if (doc.studyList[idx].focusId!="" && doc.studyList[idx].focusId!=null) { 
var pole = doc.studyList[idx].focusId.split(/[ -]+/);
for (var i=0; i<pole.length;i++) {
emit([pole[i]], [doc.parentId, {'_id': doc.parentId}]);
}
 }
}
}

_design/fields/_view/focusIdtest2?include_docs=true

{"id":"13430","key":["1002"],"value":["13000",{"_id":"13000"}],"doc":{"_id":"13430" ...


Can help how make work View2? 

I can use array in value but doesn't work in this example.

Thanks all to help.

Ladislav 




Re: Problems with array with include_docs

Posted by Paul Davis <pa...@gmail.com>.
include_docs won't work when the _id is nested in an array like that.
Your value *must* be an object that contains an _id member.

On Mon, May 30, 2011 at 10:35 AM, Ladislav Prskavec
<la...@prskavec.net> wrote:
> Hello,
> i have problem with my views. View 1 work's fine, geting parent document by _id, but in View 2 by include_docs=true not get parent document requested by '_id': XXX.
>
> # View 1
>
> function(doc) {
> for (var idx in doc.studyList) {
>  if (doc.studyList[idx].focusId!="" && doc.studyList[idx].focusId!=null) {
> var pole = doc.studyList[idx].focusId.split(/[ -]+/);
> for (var i=0; i<pole.length;i++) {
> emit([pole[i], doc.parentId], {'_id': doc.parentId});
> }
>  }
> }
> }
>
>
> _design/fields/_view/focusIdtest?include_docs=true
>
> {"id":"7L000","key":["1002",0],"value":{"_id":0},"doc":null},
> {"id":"13430","key":["1002","13000"],"value":{"_id":"13000"},"doc":{"_id":"13000","_rev" ...
>
>
> # View 2
>
> function(doc) {
> for (var idx in doc.studyList) {
>  if (doc.studyList[idx].focusId!="" && doc.studyList[idx].focusId!=null) {
> var pole = doc.studyList[idx].focusId.split(/[ -]+/);
> for (var i=0; i<pole.length;i++) {
> emit([pole[i]], [doc.parentId, {'_id': doc.parentId}]);
> }
>  }
> }
> }
>
> _design/fields/_view/focusIdtest2?include_docs=true
>
> {"id":"13430","key":["1002"],"value":["13000",{"_id":"13000"}],"doc":{"_id":"13430" ...
>
>
> Can help how make work View2?
>
> I can use array in value but doesn't work in this example.
>
> Thanks all to help.
>
> Ladislav
>
>
>
>