From user-return-5448-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Thu Jul 09 00:12:54 2009 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 69416 invoked from network); 9 Jul 2009 00:12:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 9 Jul 2009 00:12:54 -0000 Received: (qmail 46272 invoked by uid 500); 9 Jul 2009 00:13:03 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 46186 invoked by uid 500); 9 Jul 2009 00:13:03 -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 46176 invoked by uid 99); 9 Jul 2009 00:13:03 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Jul 2009 00:13:03 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [209.85.222.192] (HELO mail-pz0-f192.google.com) (209.85.222.192) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Jul 2009 00:12:55 +0000 Received: by pzk30 with SMTP id 30so761641pzk.30 for ; Wed, 08 Jul 2009 17:12:34 -0700 (PDT) MIME-Version: 1.0 Received: by 10.142.246.19 with SMTP id t19mr33580wfh.178.1247098354227; Wed, 08 Jul 2009 17:12:34 -0700 (PDT) In-Reply-To: References: Date: Thu, 9 Jul 2009 10:12:34 +1000 Message-ID: <55047b710907081712v3fa789e9ya3d7491dcedc9df3@mail.gmail.com> Subject: Re: best way to map this? From: Nicholas Orr To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=000e0cd2e6e6675938046e3ab646 X-Virus-Checked: Checked by ClamAV on apache.org --000e0cd2e6e6675938046e3ab646 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit One thing you'd need to do is for(project in doc.projects) { } right now looking at what your doing your asking for the projectid property of an array, which isn't what you want... I don't know about the other stuff, this is one thing I noticed. Nick On Thu, Jul 9, 2009 at 5:29 AM, Warner Onstine wrote: > Hi all, I'm fairly new to CouchDB and have been reading through the > wiki and different articles online relating to this. > > I have two documents: > - Project > - User > > A project will have many users, and a user can belong to more than one > project. Initially I set it up like this: > Project > - id = "project_[name]" (where name is below) > - name = [name] > - type = "project" > etc. > > User > - id = "[User's name]" > - type = "user" > - projects = [{"project_id" = "[a specific project]", "role" = > "developer" (or something else)}, ...(other projects)] > > I then created a collation view (which I'm still playing with, having > an issue with the multiple projects part for a developer): > function(doc) { > if(doc.type == "project") { > emit([doc._id, 0], doc); > } else if (doc.type == "user") { > emit([doc.projects.project_id, 1], doc); > } > } > > I've been looking at creating another document called project_users > (rather a new type) that I can join on, but then read the entity > relationship doc and it says it will require multiple queries to get > all the data for this type of join. > > There does exist the possibility that a user will be updating their > info while someone else is attempting to add them to a project (thus > creating a conflict). > > Looking for others thoughts on this. Thanks! > > -warner > --000e0cd2e6e6675938046e3ab646--