Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 47557 invoked from network); 17 Apr 2010 06:37:35 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 17 Apr 2010 06:37:35 -0000 Received: (qmail 62048 invoked by uid 500); 17 Apr 2010 06:37:34 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 61774 invoked by uid 500); 17 Apr 2010 06:37:31 -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 61763 invoked by uid 99); 17 Apr 2010 06:37:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 17 Apr 2010 06:37:31 +0000 X-ASF-Spam-Status: No, hits=2.5 required=10.0 tests=FREEMAIL_FROM,FREEMAIL_REPLY,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of simonmetson@googlemail.com designates 74.125.82.52 as permitted sender) Received: from [74.125.82.52] (HELO mail-ww0-f52.google.com) (74.125.82.52) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 17 Apr 2010 06:37:24 +0000 Received: by wwd20 with SMTP id 20so470164wwd.11 for ; Fri, 16 Apr 2010 23:37:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:mime-version :subject:date:references:x-mailer; bh=4ZGtZKosK3aFtOJTSZWTZ2cK7Rty3YV9lVb4Qql4Zgg=; b=HkG9Fz8nVr2b99iWOPvSNaDzWyIygiUFoTHMiN6eh4GfEw+g9bjZhq9LbGNeyEs4SG Z5HtNbgG0ouP9X6bpbCS9Q/jb9BuXEzjLidjv+yqZNnh+LtXg79MKI5CVDpbXyXMF9AD /C/bBmYtzXHooSEdiZL9j0RB807IkI0H/LX6U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:from:to:in-reply-to:content-type :content-transfer-encoding:mime-version:subject:date:references :x-mailer; b=cyFNOv0mMY6zUUJ2vFKIMc2zpk6xhGVksjf8LGLVxxg5539v7wXwgLLGPu+I7hvIcW 3rVlHzBuTa3Lio7A6Vh1OPlfD/ztd1WBnA87fvyW6DOfOIdOAtMaL1br8FcDDHrvtiuz RGy//lamoOdbAqkE2e4FAy6MqK0ee/jMFOaLQ= Received: by 10.216.87.194 with SMTP id y44mr3228290wee.157.1271486223499; Fri, 16 Apr 2010 23:37:03 -0700 (PDT) Received: from macbookpro.lan (93-97-111-13.zone5.bethere.co.uk [93.97.111.13]) by mx.google.com with ESMTPS id z34sm27533724wbv.20.2010.04.16.23.37.02 (version=SSLv3 cipher=RC4-MD5); Fri, 16 Apr 2010 23:37:03 -0700 (PDT) Message-Id: <37323EC8-2A4A-474E-8E79-EA1DB540A441@googlemail.com> From: Simon Metson To: user@couchdb.apache.org In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Apple Message framework v936) Subject: Re: getting most recent doc Date: Sat, 17 Apr 2010 07:37:01 +0100 References: X-Mailer: Apple Mail (2.936) X-Virus-Checked: Checked by ClamAV on apache.org Hi, If your timestamp is the time couchdb gets the document could = you =20 possibly ditch the view and just use _changes? Cheers Simon On 16 Apr 2010, at 09:46, wolfgang haefelinger wrote: > Thanks Robert > > for your answer. However, it is not exactly what I was looking for > (due to my inappropriate problem description). > > Firstly, I do want to have the document instead of the time stamp in > order to avoid that additional document fetch. That's obviously easy > to fix: > > function(doc) { // > emit([doc.name, doc.timestamp], doc); > } > > However, in my original attempt I can easily get an overview over all > categories using "group=3Dtrue". And again my apologies for not having > mentioned this - that's what I actually want: > * I want to have an overview over all "categories" where each category > is associated with the most recent event (document). > * Another goal is to limit the traffic to a minimum, i.e. I don't want > to discard or skip items returned by the (couchdb) server. > > Your map function works fine - if I know the category names in > advance. Assume that I have N categories. Then I have to query the > server N+1 times in order to present the overview (1 query to get all > categories and N queries to get most recent event document). > > This is exactly the same as my second attempt: 1 query to get > categories and most recent document id plus N simple get queries > fetching documents. But what I was wondering is, whether I can avoid > that extra N queries? > > // Regards > > P.S.: > Obviously is your example more flexible as it would very easily allow > me to calculate the most N recent events. > > P.P.S.: > Btw, I had some hard times regarding parameter "descending" which is > IMHO harmful documented ("reverse the output" =3D> no, not at all!) = and > inappropriate named. What "descending" does is changing the "key > traversal order", not more and not less. The output of that traversal > is unchanged. > > > > > > On Fri, Apr 16, 2010 at 12:42 AM, Robert Newson = > wrote: >> Something like; >> >> map; >> function(doc) { >> emit([doc.name, doc.timestamp], null); >> } >> >> no reduce method. >> >> with calls like; >> >> http://localhost:5984/db/_design/ddoc/_view/view?startkey=3D["name",=20= >> {}]&endkey=3D["name"]&descending=3Dtrue&limit=3D1 >> >> should get you the latest (highest timestamp) for document with >> doc.name of "name" >> >> On Thu, Apr 15, 2010 at 11:33 PM, wolfgang haefelinger >> wrote: >>> My apologies for asking a probably rather stupid question .. >>> >>> Docs in my database are events. An event has a category name, a time >>> stamp and lots of other details. I am looking for the most recent >>> event. >>> >>> I started with something like >>> >>> function (doc) { // map >>> emit(doc.name,doc) >>> } >>> >>> function (ks,vs,rr) { >>> var maxdoc =3D max_timestamp(vs); >>> return maxdoc; >>> } >>> >>> Although I'm reducing considerably, couchdb complains that I'm not >>> reducing hard enough :-) >>> >>> (* Btw, what is actually the "reduce" limit? Do attachments count =20= >>> as well? *) >>> >>> Then I tried something like >>> >>> function (doc) { >>> emit(doc.name,{ "_id" : doc._id, "ts" : doc.timestamp}); >>> } >>> >>> and with a "virtually" unchanged reduce function. Now I'm below >>> couchdb's reduction limit. However, this view does not return the =20= >>> most >>> recent document I was looking for but the "id" of that document. >>> >>> I had some hope that query parameter "include_docs=3Dtrue" would do =20= >>> the >>> magic (that's why I used "_id" as property name). But then I learned >>> that "include_docs" is not supported for "reduced" views which =20 >>> took me >>> by surprise. What could be the rational for this behaviour? >>> >>> In summary: >>> * Is there a way to get the "most recent" document via a view? >>> >>> // Regards >>> >> > > > > --=20 > Wolfgang H=E4felinger > h=E4felinger IT - Applied Software Architecture > http://www.haefelinger.it > +31 648 27 61 59