From couchdb-user-return-1403-apmail-incubator-couchdb-user-archive=incubator.apache.org@incubator.apache.org Wed Oct 01 02:30:09 2008 Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 18329 invoked from network); 1 Oct 2008 02:30:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Oct 2008 02:30:09 -0000 Received: (qmail 12660 invoked by uid 500); 1 Oct 2008 02:30:07 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 12631 invoked by uid 500); 1 Oct 2008 02:30:06 -0000 Mailing-List: contact couchdb-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-user@incubator.apache.org Delivered-To: mailing list couchdb-user@incubator.apache.org Received: (qmail 12620 invoked by uid 99); 1 Oct 2008 02:30:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Sep 2008 19:30:06 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jwall@google.com designates 216.239.33.17 as permitted sender) Received: from [216.239.33.17] (HELO smtp-out.google.com) (216.239.33.17) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Oct 2008 02:29:06 +0000 Received: from wpaz37.hot.corp.google.com (wpaz37.hot.corp.google.com [172.24.198.101]) by smtp-out.google.com with ESMTP id m912S5r1017814 for ; Wed, 1 Oct 2008 03:28:06 +0100 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1222828086; bh=qTTV9W9O61meY71VgCg7gDeL/mE=; h=DomainKey-Signature:Message-ID:Date:From:To:Subject:In-Reply-To: MIME-Version:Content-Type:References; b=NrCzh4CxqRLBSUYVUm5V/kLAsD ilX6pAblwyPn+c7/HF+5uZCZpARCKWfouTHqzNG2tMNlOZY6B/lIf0PzmbVA== DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=message-id:date:from:to:subject:in-reply-to:mime-version: content-type:references; b=Q3q59lOfcaIce/jabnqLP/pEyHupXnWw8cK/zreb59QZ7xJOPlKMfv8IWPjXrUwvW LSyZ9wqdqibwad5r7E6Ag== Received: from fg-out-1718.google.com (fgbl26.prod.google.com [10.86.88.26]) by wpaz37.hot.corp.google.com with ESMTP id m912S3S1030602 for ; Tue, 30 Sep 2008 19:28:03 -0700 Received: by fg-out-1718.google.com with SMTP id l26so242212fgb.20 for ; Tue, 30 Sep 2008 19:28:02 -0700 (PDT) Received: by 10.187.235.19 with SMTP id m19mr1082211far.5.1222828082786; Tue, 30 Sep 2008 19:28:02 -0700 (PDT) Received: by 10.187.160.11 with HTTP; Tue, 30 Sep 2008 19:28:02 -0700 (PDT) Message-ID: <7c40ded80809301928k77abe94awde7c65433b717c47@mail.gmail.com> Date: Tue, 30 Sep 2008 21:28:02 -0500 From: "Jeremy Wall" To: couchdb-user@incubator.apache.org Subject: Re: Associating users and comments In-Reply-To: <2098F155-ECB7-468E-8CA7-8E54F18EE606@groovie.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_91448_28506566.1222828082771" References: <2098F155-ECB7-468E-8CA7-8E54F18EE606@groovie.org> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_91448_28506566.1222828082771 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline If user and document all have unique identifiers then just recording the identifier as linking metadata in the document should be enough. The user and document info can change but the id never does. The Autogenerated Document ID's that couchdb creates for you would be perfect. This is how do it for the CouchDB backed CMS I'm building. On Tue, Sep 30, 2008 at 9:10 PM, Ben Bangert wrote: > I have a setup similar to what Chris Lenz documented with comments and > posts that they go to. However, since user data changes, I'd like to figure > out a way to get back the user record either before or after the comment > they made rather than having the relevant user data inside every comment > posted (which would require a ton of updates should the user info change). > > So given a database with types of post, comment, user, how would I get back > a few posts, with their comments, and with the comment posters full name > (which is in a separate document)? > > Also, with regards to the originally documented trick to return both custom > and order documents: > > function(doc) { > if (doc.Type == "customer") { > emit([doc._id, 0], doc); > } else if (doc.Type == "order") { > emit([doc.customer_id, 1], doc); > } > } > > From my understanding, imposing a count limit on this doesn't discriminate > between customers or orders, just total rows returned from the view. So how > would I say, give me back 5 customers with their orders? Or even, give me > back 10 customers with their last 5 orders? With a reduce you can can take the map results and order/combine them in whatever data structure you want. Then using start_key and end_key with count you can page through the results. Say for instance: function(key, values) { if( key[1] == 0 ) { } > > > Cheers, > Ben ------=_Part_91448_28506566.1222828082771--