another way (useless in your case) is to keep messages as separate docs, and keep a cache of the structure of the tree (id,(id,id)...)) as another doc. if u have the notion of closed/frozen threads, that might be of use. actualy that cache can be a dict: { parent_id: [ list of children_id ] } svil On Fri, 22 Feb 2013 18:14:49 +1300 Michael Heuberger wrote: > thanks andrey and svil > > depth is infinite. in theory a message can have million replies forth > and back. similar like a very long email thread. > > i think storing ancestors à la andrey would be too much hassle but > works well for few levels. > > svil, what did you mean with dicts and with keeping all children in > one doc? can you tell me more? > > thanks, > michael > > On 22/02/13 17:27, svilen wrote: > > my rough guess: > > > > if it's finite depth, then all in one doc: > > - list of (item or (list of ...)) > > - or same with dicts > > > > else, one doc per message keeping just link-to-parent, > > or multiple links-to-grand...grand-parents and/or root. > > similar to the strategies in SQL - nested etc. > > keeping all chidlren of same node in one doc is also possible.. > > > > in any case either traversal or storing or both will be > > difficult. > > > > ciao > > svil > > > > On Fri, 22 Feb 2013 17:13:01 +1300 > > Michael Heuberger 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 > >> > > -- > > 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 >