couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sean Copenhaver <sean.copenha...@gmail.com>
Subject Re: couchDB and node.js double bind
Date Sun, 22 May 2011 20:52:02 GMT
If the relationships were bi-directional then perhaps your map function could look like this:

function(doc) {
emit([doc._id], null);
for(var i = 0; i < doc.related.length; i++){
emit([doc.related[i], doc._id], null);
}
}

When you query for a specific doc id you would get that document plus all the other related
documents. Something like:

_view/view?startkey=[<id>],include_docs=true

If they were one way then yeah, I believe you would need to do some looping or make a second
request.

-- 
Sean Copenhaver
Sent with Sparrow
On Sunday, May 22, 2011 at 4:38 PM, MK wrote: 
> On Sun, 22 May 2011 14:12:05 -0400
> Sean Copenhaver <sean.copenhaver@gmail.com> wrote:
> > I hope I understand what you are after, but here's what I got. You
> > have a parent document that has a list of ids for it's children or
> > some sort of related documents? You want to be able to query for the
> > parent in the relationship and get a list of children ids with a
> > short description?
> > 
> > Sounds like you need to reverse the relationship (or make it
> > bi-directional). Have the children keep an id to their parent
> 
> All the documents have exactly the same structure -- there is no
> parent/child relation -- which includes a short description and an
> array of other (identically structured docs) to which this one is
> related. I want to display one of these, and in the display, list the
> related docs including their short desc.
> 
> 
> -- 
> "Enthusiasm is not the enemy of the intellect." (said of Irving Howe)
> "The angel of history[...]is turned toward the past." (Walter Benjamin)
> 

Mime
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message