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 D72BEBCF4 for ; Mon, 2 Jan 2012 20:57:33 +0000 (UTC) Received: (qmail 40132 invoked by uid 500); 2 Jan 2012 20:57:32 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 40036 invoked by uid 500); 2 Jan 2012 20:57:32 -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 40020 invoked by uid 99); 2 Jan 2012 20:57:32 -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 20:57:32 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of joerlend.schinstad@gmail.com designates 74.125.83.52 as permitted sender) Received: from [74.125.83.52] (HELO mail-ee0-f52.google.com) (74.125.83.52) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Jan 2012 20:57:22 +0000 Received: by eeke52 with SMTP id e52so16338468eek.11 for ; Mon, 02 Jan 2012 12:57:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=jbZNbsmk2bK7TwTkd419bGm/DsPn+kLB2Culk6llj6g=; b=cpmPUbSPQBILjj4nYPztQ5hD1zwbsDgkL52zD7VWLs9IaKPMCLP+fMBY0/3kY1aknG 9Mwmfp67diPdDqcDKEvSBomRmaFWmulkVwh/V9Zukoi3Mh1/4em5hxgF7aRE2QMQBaIU OIvMICNPprC0cNtKD6QcwSaBGkfd94DCgDDP0= Received: by 10.14.22.10 with SMTP id s10mr20279084ees.122.1325537822270; Mon, 02 Jan 2012 12:57:02 -0800 (PST) Received: from [10.0.0.6] (163.80-202-166.nextgentel.com. [80.202.166.163]) by mx.google.com with ESMTPS id y12sm195175377eeb.11.2012.01.02.12.57.00 (version=SSLv3 cipher=OTHER); Mon, 02 Jan 2012 12:57:01 -0800 (PST) Message-ID: <4F021A1D.4010502@gmail.com> Date: Mon, 02 Jan 2012 21:57:01 +0100 From: Jo-Erlend Schinstad User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111229 Thunderbird/9.0 MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: Modeling a tree in couchdb. References: <4EF45C4A.5080902@gmail.com> <4F0164FE.7050207@gmail.com> <4F01E3A1.2080402@gmail.com> In-Reply-To: <4F01E3A1.2080402@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Den 02. jan. 2012 18:04, skrev Kevin R. Coombes: > 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. > That was my original thought. I wanted to do something like key [0, 5, 4,2] which would mean the sixth child of the first top-level node, and the fifth child of that node and the third of it. This would work well, and I would get the tree in one go, organized and nice. The problem is that the tree must be reorganizable. In that model, if moved one node, then I would have to update all the following documents. If there's a million rows in the tree, then I would need something like 999.990+ http requests... :) Further, one of primary goals is replication. It could never work. The internet janitor would hit me in the back of the head with a wrench. However, for something like a family tree or a blog, where something will forever be a response to something else, that would work nicely. So what I'm doing now, is that I'm just retrieving the data from the database and organising it on the client. It's not a comfortable solution, I think. It's not elegant, but if it's the only possible solution, then it doesn't really matter if it's elegant or not. :) In other words, I'm still very much looking for a good way to model a flexible tree in a couchdb. Any suggestions are highly welcome. Jo-Erlend Schinstad