Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 96128 invoked from network); 14 Jun 2010 22:54:03 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 14 Jun 2010 22:54:03 -0000 Received: (qmail 37793 invoked by uid 500); 14 Jun 2010 22:54:02 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 37719 invoked by uid 500); 14 Jun 2010 22:54:01 -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 37711 invoked by uid 99); 14 Jun 2010 22:54:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Jun 2010 22:54:01 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of darran.m.white@gmail.com designates 74.125.82.180 as permitted sender) Received: from [74.125.82.180] (HELO mail-wy0-f180.google.com) (74.125.82.180) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Jun 2010 22:53:53 +0000 Received: by wyg36 with SMTP id 36so5322066wyg.11 for ; Mon, 14 Jun 2010 15:53:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=/ZMvBfHpDHSZWC9NphzZm2NH6NtZDAI+D8llw5Ma/oc=; b=YXq8XPeSULH1bfVHAgyqK6kMVHiQM+o4bX/h+2iqC/RaQanaF8ifqfHujSqad23StZ /6qP2w2FyDvQuJSpvdjAgCVdZH8PJuiHFLRbyCQybQcozjjdZHSDQD/KbLTDaGrwaP13 qXWjFL6O3Bb95EFsxBkF3UgNzBejohhJjQmeQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=H0AjuQEB4fwhyWgSdxXHl2qyXXhqu1OXA+fOKLGoawG2jEZA1Y0vN8Ht/U6gXJ28eB k3BBYplxH4WEohSUEFILds74Ew+4aJhDuQcCxIafszjcYGg99G9OskqwRdzUvoxKMwiv l85l+4mCQdBYV7kGIflUIpo5wpEyMgAI3CeBs= MIME-Version: 1.0 Received: by 10.216.88.132 with SMTP id a4mr3017198wef.16.1276556012924; Mon, 14 Jun 2010 15:53:32 -0700 (PDT) Received: by 10.216.28.212 with HTTP; Mon, 14 Jun 2010 15:53:32 -0700 (PDT) Date: Mon, 14 Jun 2010 23:53:32 +0100 Message-ID: Subject: Select row with a count of 1 after reduce From: Darran White To: CouchDB users mailing list Content-Type: multipart/alternative; boundary=0016e6d975aaafb0dd0489055bca X-Virus-Checked: Checked by ClamAV on apache.org --0016e6d975aaafb0dd0489055bca Content-Type: text/plain; charset=ISO-8859-1 Hi, I have the following view:- function(doc) { if(doc.doctype=='job'){ emit([doc._id,doc.createdDate,'UNASSIGNED','CREATED'], doc._id); }else if(doc.doctype=='jobTask'){ emit([doc.jobId,doc.taskLatestDate,'ASSIGNED',doc.taskName],doc.jobId); } } So I have a Job and a JobTask the JobTask holds a reference to the Job in a jobId field. What I would like to do is select all the jobs which don`t have any associated JobTasks. I was thinking of using a simple reduce function :- function(keys, values, rereduce) { return values.length; } So with a data set: ["0e482a01111e0c0932112f73c8001f68", "13-06-2010 20:42:22:613", "ASSIGNED", "ACTIVE"] ["0e482a01111e0c0932112f73c8001f68", "13-06-2010 20:40:13:423", "UNASSIGNED", "CREATED"] ["0e482a01111e0c0932112f73c80011ca", "13-06-2010 15:36:13:371", "UNASSIGNED", "CREATED"] ["0e482a01111e0c0932112f73c800116a", "13-06-2010 19:20:48:541", "ASSIGNED", "ACTIVE"] ["0e482a01111e0c0932112f73c800116a", "13-06-2010 15:35:59:912", "UNASSIGNED", "CREATED"] ["0e482a01111e0c0932112f73c80005a5", "13-06-2010 19:20:48:507", "ASSIGNED", "WIP"] ["0e482a01111e0c0932112f73c80005a5", "13-06-2010 15:33:02:947", "UNASSIGNED", "CREATED"] It would be reduced to: ["0e482a01111e0c0932112f73c8001f68"] 2 ["0e482a01111e0c0932112f73c80011ca"] 1 ["0e482a01111e0c0932112f73c800116a"] 2 ["0e482a01111e0c0932112f73c80005a5"] 2 I would then like to select all those rows which have a count of 1 and load the associated documents. However I`m not sure on how to select only those which have a value of 1 or if this is possible. I was thinking of maybe using a list function to only return those ids where the value is 1 would this be the right way to approach this? Another idea would be to get the latest date so ["0e482a01111e0c0932112f73c8001f68", "13-06-2010 20:42:22:613", "ASSIGNED", "ACTIVE"] ["0e482a01111e0c0932112f73c8001f68", "13-06-2010 20:40:13:423", "UNASSIGNED", "CREATED"] ["0e482a01111e0c0932112f73c80005a5", "13-06-2010 19:20:48:507", "ASSIGNED", "WIP"] ["0e482a01111e0c0932112f73c80005a5", "13-06-2010 15:33:02:947", "UNASSIGNED", "CREATED"] ["0e482a01111e0c0932112f73c80011ca", "13-06-2010 15:36:13:371", "UNASSIGNED", "CREATED"] Would return ["0e482a01111e0c0932112f73c8001f68", "13-06-2010 20:42:22:613", "ASSIGNED", "ACTIVE"] ["0e482a01111e0c0932112f73c80005a5", "13-06-2010 19:20:48:507", "ASSIGNED", "WIP"] ["0e482a01111e0c0932112f73c80011ca", "13-06-2010 15:36:13:371", "UNASSIGNED", "CREATED"] I could then filter on "CREATED" I`m aware of the limit function but I need to get the latest entry for all documents does any one have an idea on how to do this? thanks Darran --0016e6d975aaafb0dd0489055bca--