How to reference other documents in a couchDB view (joining like functionality)
- by Surfrdan
We have a CouchDB representation of an XML database which we use to power a javascript based frontend for manipulating the XML documents. The basic structure is a simple 3 level hierachy. i.e.
A - B - C
A: Parent doucument (type A)
B: any number of child documents of parent type A
C: any number of child documents of parent type B
We represent these 3 document types in CouchDB with a 'type' attribute:
e.g.
{
"_id":"llgc-id:433",
"_rev":"1-3760f3e01d7752a7508b047e0d094301",
"type":"A",
"label":"Top Level A document",
"logicalMap":{
"issues":{
"1":{
"URL":"http://hdl.handle.net/10107/434-0",
"FILE":"llgc-id:434"
},
"2":{
"URL":"http://hdl.handle.net/10107/467-0",
"FILE":"llgc-id:467"
etc...
}
}
}
}
{
"_id":"llgc-id:433",
"_rev":"1-3760f3e01d7752a7508b047e0d094301",
"type":"B",
"label":"a B document",
}
What I want to do is produce a view which returns documents just like the A type but includes the label attribute from the B document within the logicalMap list e.g.
{
"_id":"llgc-id:433",
"_rev":"1-3760f3e01d7752a7508b047e0d094301",
"type":"A",
"label":"Top Level A document",
"logicalMap":{
"issues":{
"1":{
"URL":"http://hdl.handle.net/10107/434-0",
"FILE":"llgc-id:434",
"LABEL":"a B document"
},
"2":{
"URL":"http://hdl.handle.net/10107/467-0",
"FILE":"llgc-id:467",
"LABEL":"another B document"
etc...
}
}
}
}
I'm struggling to get my head around the best way to perform this. It looks like it should be fairly simple though!