Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D5897B00F for ; Mon, 2 Jan 2012 17:05:11 +0000 (UTC) Received: (qmail 40668 invoked by uid 500); 2 Jan 2012 17:05:10 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 40408 invoked by uid 500); 2 Jan 2012 17:05:08 -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 40400 invoked by uid 99); 2 Jan 2012 17:05:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Jan 2012 17:05:08 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of kevin.r.coombes@gmail.com designates 209.85.161.180 as permitted sender) Received: from [209.85.161.180] (HELO mail-gx0-f180.google.com) (209.85.161.180) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Jan 2012 17:04:59 +0000 Received: by ggnq1 with SMTP id q1so11716688ggn.11 for ; Mon, 02 Jan 2012 09:04:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:organization:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type; bh=xiFw2y2Cnb8z5On/EWsHxNQAIiqPgFkIlqLwosbiwag=; b=axRdwgyc681KporLLIKkLLKtCOCF8erdTEz82pANTy1wBhudtjvfkO1iw9LaMIK0Dq KcW9iDduJ24m0zwlm6++2LzQbiKfYYwoujtTWDC1FklbbLURNNtXEBXQJfG/Oam4kino yyZCeHYzQPJFl/59s1kGUSSg5l67dmJZRpErg= Received: by 10.100.200.1 with SMTP id x1mr19444946anf.45.1325523878299; Mon, 02 Jan 2012 09:04:38 -0800 (PST) Received: from [10.105.35.136] ([143.111.22.28]) by mx.google.com with ESMTPS id m38sm118822516anq.16.2012.01.02.09.04.35 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 02 Jan 2012 09:04:36 -0800 (PST) Message-ID: <4F01E3A1.2080402@gmail.com> Date: Mon, 02 Jan 2012 11:04:33 -0600 From: "Kevin R. Coombes" Organization: UT M.D. Anderson Cancer Center User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: user@couchdb.apache.org CC: Walter Werner Subject: Re: Modeling a tree in couchdb. References: <4EF45C4A.5080902@gmail.com> <4F0164FE.7050207@gmail.com> In-Reply-To: Content-Type: multipart/alternative; boundary="------------000507030209030101020609" X-Virus-Checked: Checked by ClamAV on apache.org --------------000507030209030101020609 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: >> 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 --------------000507030209030101020609--