couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Hobson <>
Subject Re: Delete document Tree Structure
Date Fri, 28 May 2010 08:47:59 GMT
Hi Arun,

I'm even newer to couch. How I would approach your problem...

Start a list with the ID of B.
Step down the list with current element x until there are no more elements.
find the ids of all children of e (x.parentID = e._id)
for each id found
if it is not in the list, append it to the list
else (your tree is cyclic).
delete all elements in the list.

To work this through:...
Start with a list of {B}.
The first loop will look for children of B, find C and E and add them to 
the list
giving {B,C,E}
Next loop, will look for the children of C, and finds none
Then it looks for the children of E, finds F and adds it to the list 
(now {B,C,E,F})
Last cycle, it looks for the children of F and finds none.
Then it finds no element on the list to process, so it deletes all ids 
in the list {B, C, E, F }

You may have to write your own code to get the next element from the 
list. Many built-in routines will get confused by the additions.

To provide a consistent view for others, you may wish to consider the 
order you delete them in. If you have deleted the parent first, others 
will fail to reach it from the child! You can delete child-first by 
working back down the list.

Don't forget the check that the id is not already in the list. If you 
miss this, and the tree ever has a cycle, your program will blow up with 
an out of memory error.



On 27/05/2010 06:21, Aun... สุวพรหม wrote:
> in my design , i just keep parent id of each documents.
>>        I design document in couchdb to have relation something like
>>               directory
>>                     |
>>                     A---------D
>>                     |
>>                     B---------C
>>                                  |
>>                                  |
>>                                  E ------F
> No virus found in this incoming message.
> Checked by AVG -
> Version: 9.0.819 / Virus Database: 271.1.1/2897 - Release Date: 05/26/10 07:25:00

View raw message