title: How to reference other documents in a couchDB view (joining like functionality)
body: <p>We have a CouchDB representation of an XML database which we use to power a javascript based front-end for manipulating the XML documents. The basic structure is a simple 3 level hierarchy. i.e.</p>
  <p>A -&gt; B -&gt; C</p>
  <ul>
  <li>A: Parent document (type A)</li>
  <li>B: any number of child documents of parent type A</li>
  <li>C: any number of child documents of parent type B</li>
  </ul>
  <p>We represent these 3 document types in CouchDB with a <code>type</code> attribute:</p>
  <p>e.g.</p>
  <pre><code>{
  &quot;_id&quot;:&quot;llgc-id:433&quot;,
  &quot;_rev&quot;:&quot;1-3760f3e01d7752a7508b047e0d094301&quot;,
  &quot;type&quot;:&quot;A&quot;,
  &quot;label&quot;:&quot;Top Level A document&quot;,
  &quot;logicalMap&quot;:{
      &quot;issues&quot;:{
          &quot;1&quot;:{
              &quot;URL&quot;:&quot;http://hdl.handle.net/10107/434-0&quot;,
              &quot;FILE&quot;:&quot;llgc-id:434&quot;
          },
          &quot;2&quot;:{
              &quot;URL&quot;:&quot;http://hdl.handle.net/10107/467-0&quot;,
              &quot;FILE&quot;:&quot;llgc-id:467&quot; 
          etc...
          }
      }
  }
  }
  
  
  {
  &quot;_id&quot;:&quot;llgc-id:433&quot;,
  &quot;_rev&quot;:&quot;1-3760f3e01d7752a7508b047e0d094301&quot;,
  &quot;type&quot;:&quot;B&quot;,
  &quot;label&quot;:&quot;a B document&quot;,
  }
  </code></pre>
  <p>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.</p>
  <pre><code>{
  &quot;_id&quot;:&quot;llgc-id:433&quot;,
  &quot;_rev&quot;:&quot;1-3760f3e01d7752a7508b047e0d094301&quot;,
  &quot;type&quot;:&quot;A&quot;,
  &quot;label&quot;:&quot;Top Level A document&quot;,
  &quot;logicalMap&quot;:{
      &quot;issues&quot;:{
          &quot;1&quot;:{
              &quot;URL&quot;:&quot;http://hdl.handle.net/10107/434-0&quot;,
              &quot;FILE&quot;:&quot;llgc-id:434&quot;,
              &quot;LABEL&quot;:&quot;a B document&quot;
          },
          &quot;2&quot;:{
              &quot;URL&quot;:&quot;http://hdl.handle.net/10107/467-0&quot;,
              &quot;FILE&quot;:&quot;llgc-id:467&quot;,
              &quot;LABEL&quot;:&quot;another B document&quot; 
          etc...
          }
      }
  }
  }
  </code></pre>
  <p>I'm struggling to get my head around the best way to perform this. It looks like it should be fairly simple though!</p>