Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 83596 invoked from network); 28 Apr 2009 05:43:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 Apr 2009 05:43:16 -0000 Received: (qmail 51137 invoked by uid 500); 28 Apr 2009 05:43:15 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 51063 invoked by uid 500); 28 Apr 2009 05:43:15 -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 51053 invoked by uid 99); 28 Apr 2009 05:43:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Apr 2009 05:43:15 +0000 X-ASF-Spam-Status: No, hits=1.5 required=10.0 tests=NORMAL_HTTP_TO_IP,SPF_PASS,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of paul.joseph.davis@gmail.com designates 209.85.198.239 as permitted sender) Received: from [209.85.198.239] (HELO rv-out-0506.google.com) (209.85.198.239) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Apr 2009 05:43:07 +0000 Received: by rv-out-0506.google.com with SMTP id g37so197078rvb.35 for ; Mon, 27 Apr 2009 22:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=wc0DN8lVFRSkOMrvWg1WZXX0SRTq9Acotfk4QwQh1Ts=; b=lt3LPOh/m6xzF6B2Iq9E2rkkbJo7SFtJUBsts8k7ff+kHrT9hifWmhM4k84MRrU6MX w445jEmNQwo91x9X/nqW5YQHHs9WTwfFLjWjxEEdZrjU+E61w0WZeOubzrj/rnrkjagR iNTEx3Tdykfo4q/KdzXgnVsO6dvT81IY1aAXA= DomainKey-Signature: a=rsa-sha1; c=nofws; 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; b=CzwHSMC871czSOg5FquoYe0U6AhRiXdkXeZkjeeVuPuz3ZHMl5byp06cAPdXgBDdAY em8RQ4fijqNu82RjIeNX6uhSKl4N/FeAU2jlycTMUNUI4Q64CuZcCAVivWY7VMQ2sssd QOimuE7L4fPJoVYAEBs/oY8MOWkQIBJ9gBvS8= Received: by 10.114.161.11 with SMTP id j11mr3044447wae.105.1240897365714; Mon, 27 Apr 2009 22:42:45 -0700 (PDT) Received: from ?192.168.2.61? (adsl-99-148-123-134.dsl.pltn13.sbcglobal.net [99.148.123.134]) by mx.google.com with ESMTPS id d20sm3328010waa.47.2009.04.27.22.42.43 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 27 Apr 2009 22:42:43 -0700 (PDT) Message-ID: <49F69751.6080603@gmail.com> Date: Mon, 27 Apr 2009 22:42:41 -0700 From: Paul Davis User-Agent: Thunderbird 2.0.0.21 (X11/20090318) MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: map/reduce function question References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Kevin, You'll want to do something like this: { "_id": "_design/foo", "views": { "unique_names": { "map": "function(doc) {emit(doc.name, 1);}", "reduce": function(keys, values, rereduce) {return sum(values);}" } } } And then you can call this like: http://127.0.0.1:5984/db_name/_design/foo/_view/unique_names to get ouput like {"rows": [ {"key": null, "value": 3} } HTH, Paul Davis Kevin Wang wrote: > Hi All, > > While I am trying to switch my mind to map/reduce model while accessing > couchdb data, I found myself struggling. Here is a simple question that you > guys might be able to answer: > > If I have the following set of data in a doc: > > {"name": "foo", "prop": "value1"} > {"name": "bar", "prop": "value2"} > {"name": "foo", "prop": "value3"} > {"name": "bob", "prop": "value4"} > > How to write the map/reduce functions so that I can get a view which returns > the total number of unique name's? In this case, the result should be 3. > > Thanks! > > -- Kevin > >