incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrey Kuprianov <andrey.koupria...@gmail.com>
Subject Re: Tree like structures in CouchDB
Date Fri, 22 Feb 2013 04:25:09 GMT
Hi Michael,

In our case we do it by storing a whole list of ancestor IDs on the
children nodes. Then, given ancestor ID, we can pull all the children nodes
and then build tree programmatically, if so needed.

You will need a view for that, where each ancestor ID is a key. Here's a
snippet:

if(doc.ancestors) {
    for(var i in doc.ancestors) {
       emit(doc.ancestors[i], null);
    }
}
else {
    emit(null, null); /* special case where node is a root node */
}


Example of documents:

Suppose A is a parent of B and  B is a parent of C then:

A = {"_id": "A"}
B = {"_id": "B", "ancestors": ["A"]}
C = {"_id": "C", "ancestors": ["B", "A"]}


   Hope that helps,

     Andrey


On Fri, Feb 22, 2013 at 12:13 PM, Michael Heuberger <
michael.heuberger@binarykitchen.com> wrote:

> Hello guys
>
> I'd like to store messages in a tree like structure. Whenever you reply to
> a message, then the original message becomes the parent message.
>
> How would you implement something like this in CouchDB? Just curious and
> need a little guidance + advice here.
>
> Thanks,
> Michael
>
> --
>
> Binary Kitchen
> Michael Heuberger
> 4c Dunbar Road
> Mt Eden
> Auckland 1024
> (New Zealand)
>
> Mobile (text only) ...  +64 21 261 89 81
> Email ................  michael@binarykitchen.com
> Website ..............  http://www.binarykitchen.com
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message