Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 648 invoked from network); 19 Apr 2009 15:42:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 Apr 2009 15:42:43 -0000 Received: (qmail 18924 invoked by uid 500); 19 Apr 2009 15:42:43 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 18853 invoked by uid 500); 19 Apr 2009 15:42:43 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 18844 invoked by uid 500); 19 Apr 2009 15:42:43 -0000 Delivered-To: apmail-incubator-couchdb-commits@incubator.apache.org Received: (qmail 18841 invoked by uid 99); 19 Apr 2009 15:42:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Apr 2009 15:42:43 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.130] (HELO eos.apache.org) (140.211.11.130) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Apr 2009 15:42:41 +0000 Received: from eos.apache.org (localhost [127.0.0.1]) by eos.apache.org (Postfix) with ESMTP id 7E2C5118BC for ; Sun, 19 Apr 2009 15:42:19 +0000 (GMT) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Apache Wiki To: couchdb-commits@incubator.apache.org Date: Sun, 19 Apr 2009 15:42:19 -0000 Message-ID: <20090419154219.15164.22897@eos.apache.org> Subject: [Couchdb Wiki] Update of "EntityRelationship" by WoutMertens X-Virus-Checked: Checked by ClamAV on apache.org Dear Wiki user, You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification. The following page has been changed by WoutMertens: http://wiki.apache.org/couchdb/EntityRelationship The comment on the change is: Added Jason Smith's comments ------------------------------------------------------------------------------ = Modeling Entity Relationships in CouchDB = - This page is mostly a translation of Google's [http://code.google.com/appengine/articles/modeling.html Modeling Entity Relationships] article in CouchDB terms. I (WoutMertens) am mostly happy with it but it could use more code examples and more examples of actual output. Since this is a wiki, feel free to update this document to make things clearer, fix inaccuracies etc. This article is also related to [http://wiki.apache.org/couchdb/Transaction_model_use_cases Transaction model use cases] discussion, as it involves multiple document updates. + This page is mostly a translation of Google's [http://code.google.com/appengine/articles/modeling.html Modeling Entity Relationships] article in CouchDB terms. It could use more code examples and more examples of actual output. Since this is a wiki, feel free to update this document to make things clearer, fix inaccuracies etc. This article is also related to [http://wiki.apache.org/couchdb/Transaction_model_use_cases Transaction model use cases] discussion, as it involves multiple document updates. As a quick summary, this document explains how to do things that you would normally use SQL JOIN for. @@ -101, +101 @@ } }}} - or even + or even more succinctly {{{ { @@ -177, +177 @@ * ''include_docs=true'' You'll get all documents that are pertinent to the group, but in no particular order. The size of your index will be smaller though. - In general though, you want to avoid storing overly large lists of any kind in a single document. The reason is that if your document becomes, say 1MB in size, then you need to upload 1MB to the database every time you want to make a change to any part of the document. Therefore you should place the list on side of the relationship which you expect to have fewer values. In the example above, the Contact side was chosen because a single person is not likely to belong to too many groups, whereas in a large contacts database, a group might contain hundreds of members. + For the most efficient changes to the relationship list, you should place the list on side of the relationship which you expect to have fewer values. In the example above, the Contact side was chosen because a single person is not likely to belong to too many groups, whereas in a large contacts database, a group might contain hundreds of members. === Many to Many: Relationship documents === - Another way of implementing many-to-many is by creating a separate document for each relationship. A document explaining that Scott is a Friend would look like + Another way of implementing many-to-many is by creating a separate document for each relationship. + + You would use this method if you modify the key list frequently (i.e. if you get more conflicts than is acceptable), or if the key list is so large that transferring the document is unacceptably slow. Relationship documents enable frequent changes with less chance of conflict; however, you can access neither the contact nor group information in one request. You must re-request those specific documents by ID, keeping in mind that they may change or be deleted in the interim. + + A document explaining that Scott is a Friend would look like {{{ { "_id":"some unique id",