couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin R. Coombes" <kevin.r.coom...@gmail.com>
Subject Re: Modeling a tree in couchdb.
Date Mon, 02 Jan 2012 17:04:33 GMT
Take this suggestion with a grain of salt, since I haven't actually 
tried it and am just making things up....

If your structure is really a tree, then the location of every node is 
characterized by a unique path back to the root node, You could save the 
entire path in each object as a list:
     [parent, grandparent, great-grandparent, ..., rootnode]
One view would simply return this entire list for each object.
A second view would just give back the parent node.
Either view can be used (with appropriate logic in the client) to 
reconstruct the entire tree. However, you could also easily create 
auxiliary views (e.g., grandparent) depending on your needs.

This organization makes querying the tree relatively easy.  However, it 
will have _terrible _performance if you do a lot of surgery on the tree, 
lopping off branches and reattaching them in different places.

Best,
     Kevin

On 1/2/2012 2:33 AM, Walter Werner wrote:
> 2012/1/2 Jo-Erlend Schinstad<joerlend.schinstad@gmail.com>:
>> Den 02. jan. 2012 08:58, skrev Walter Werner:
>>
>>> How about if every document get a parent attribute?
>>>
>>> root document
>>> id: 123
>>> parent: undefined
>>>
>>> child document
>>> id: 768
>>> parent: 123
>>>
>>> child child document
>>> id: 991
>>> parent: 768
>>>
>>>
>>> etc.
>>>
>>> You need then a view with the parent as a key. With one request you
>>> can get all his children (only 1 level) of a document. Then you
>>> proceed with the children-documents and ask again whether they have
>>> children. Maybe it will be a performance Issue, if your 'object' has
>>> too many levels. The advantage is, that you don't have to think about
>>> how the id's of your documents should look like.
>>>
>>>
>> That is almost what I'm currently trying. I Have a topmost_parent attribute,
>> then a parent attribute and a next_sibling attribute. That way, I can get
>> all elements with one request. I still have to process on the client, but I
>> think it should work. The optimal solution would allow me to get it ordered
>> correctly from the database, but I see no way of achieving that.
>>
>> Jo-Erlend Schinstad
> Did you think about of using 2 keys in your view? One key for the
> parent attribute and the other for ordering
>
> [doc.parent, doc.timestamp]
>
> I take timestamp as an example.
>
> Walter

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