Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 28903 invoked from network); 28 May 2010 08:48:32 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 28 May 2010 08:48:32 -0000 Received: (qmail 20898 invoked by uid 500); 28 May 2010 08:48:31 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 20467 invoked by uid 500); 28 May 2010 08:48:28 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 20456 invoked by uid 99); 28 May 2010 08:48:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 May 2010 08:48:26 +0000 X-ASF-Spam-Status: No, hits=0.7 required=10.0 tests=RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [81.103.221.48] (HELO mtaout02-winn.ispmail.ntl.com) (81.103.221.48) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 May 2010 08:48:20 +0000 Received: from aamtaout04-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20100528084758.FCTW3192.mtaout02-winn.ispmail.ntl.com@aamtaout04-winn.ispmail.ntl.com> for ; Fri, 28 May 2010 09:47:58 +0100 Received: from jupiter.ianhobson.co.uk ([86.12.69.89]) by aamtaout04-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20100528084758.TLFQ1593.aamtaout04-winn.ispmail.ntl.com@jupiter.ianhobson.co.uk> for ; Fri, 28 May 2010 09:47:58 +0100 Received: (qmail 3359 invoked by uid 453); 28 May 2010 08:47:54 -0000 X-Virus-Checked: Checked by ClamAV on ianhobson.co.uk Received: from bobgriffiths.mars.hcs (HELO [192.168.0.13]) (192.168.0.13) by ianhobson.co.uk (qpsmtpd/0.40) with ESMTP; Fri, 28 May 2010 09:47:54 +0100 Message-ID: <4BFF833F.6030001@ianhobson.co.uk> Date: Fri, 28 May 2010 09:47:59 +0100 From: Ian Hobson User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.9) Gecko/20100317 Lightning/1.0b1 Thunderbird/3.0.4 ThunderBrowse/3.2.8.1 MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: Delete document Tree Structure References: <4BFDFF0A.1040508@vizrt.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Cloudmark-Analysis: v=1.1 cv=ZtHxNT4mZm3rCuM0SmWmgWxeBwJsziC8EqOrwwVkrhA= c=1 sm=0 a=q8OS1GolVHwA:10 a=IkcTkHD0fZMA:10 a=oCcaPWc0AAAA:8 a=3AuDVL9GN5LbGmC81CgA:9 a=lbxHGYD1Ii1PoLnG8JwA:7 a=On5K5aasLKagsC3hCrPOFQyMxi8A:4 a=QEXdDO2ut3YA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 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. Regards Ian 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 - www.avg.com > Version: 9.0.819 / Virus Database: 271.1.1/2897 - Release Date: 05/26/10 07:25:00 > >