Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6DA3DDF62 for ; Thu, 20 Sep 2012 11:20:57 +0000 (UTC) Received: (qmail 30196 invoked by uid 500); 20 Sep 2012 11:20:56 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 29668 invoked by uid 500); 20 Sep 2012 11:20:55 -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 29642 invoked by uid 99); 20 Sep 2012 11:20:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Sep 2012 11:20:54 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FSL_RCVD_USER,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of carl.bourne@me.com designates 17.158.236.118 as permitted sender) Received: from [17.158.236.118] (HELO nk11p04mm-asmtp009.mac.com) (17.158.236.118) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Sep 2012 11:20:48 +0000 MIME-version: 1.0 Content-type: text/plain; charset=windows-1252 Received: from [192.168.7.102] (fas011-90630-net-adsl-05.altohiway.com [213.83.104.29]) by nk11p04mm-asmtp009.mac.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Jan 3 2012)) with ESMTPSA id <0MAN00LI0BI07S50@nk11p04mm-asmtp009.mac.com> for user@couchdb.apache.org; Thu, 20 Sep 2012 11:20:26 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.7.7855,1.0.431,0.0.0000 definitions=2012-09-20_02:2012-09-20,2012-09-19,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=5 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1203120001 definitions=main-1209200082 Subject: Re: Summary view for Pie Charting From: Carl Bourne In-reply-to: Date: Thu, 20 Sep 2012 12:20:21 +0100 Content-transfer-encoding: quoted-printable Message-id: <8BD62F9F-BA40-4DDE-9D97-499AC3C9AC9E@me.com> References: <08180A01-8DC0-491C-8976-B75BBB5F95F4@me.com> <46CC7BBD-5AEC-449A-9F80-68E1AC4BB047@couchbase.com> <2A199735-20B9-4E24-9EF0-1BE43A649075@me.com> To: user@couchdb.apache.org X-Mailer: Apple Mail (2.1498) Thanks, So I'm assuming the only way to to summarise this information is to do 3 = separate queries and aggregate the results? > It's this; >=20 > map: > function(doc) { > emit(doc.date.expire, null); > } If I query against the above without a reduce (_count) function it = returns all documents according to the ?startkey=3D"2012-10-19" and not = the count which I need to build the pie chart! Am I understanding you correctly? Carl On 20 Sep 2012, at 10:11, Robert Newson wrote: > It's this; >=20 > map: > function(doc) { > emit(doc.date.expire, null); > } >=20 > and there is no reduce function. >=20 > query with ?startkey=3D"today's date minus 30 days encoded in same > format as doc.date.expire", and same for 60 and 90. >=20 > And remember to ensure that doc.date.expire sorts in the right order. > Perhaps emit it as new Date(doc.date.expire).getTime() or in ISO-8601 > formatted string. >=20 > B. >=20 >=20 > On 20 September 2012 08:04, Carl Bourne wrote: >> Jens, >>=20 >> Understand! >>=20 >> So I guess then the only way to do this is using 3 separate queries = with startkey, endkey for each time period? Then assemble the results = externally using whatever performed the query? >>=20 >> Are there any other options? >>=20 >> Regards, >>=20 >> Carl >>=20 >>=20 >> On 20 Sep 2012, at 01:18, Jens Alfke wrote: >>=20 >>> This isn=92t a valid map function, because it=92s not purely = functional =97 it uses external input in the form of the current = date/time. So if the map function is run twice on the same document, it = will not always emit the same output. That=92s not allowed. >>>=20 >>> In other words, think of what happens if you generate the index now, = and then query it 90 days from now. The information in the index = probably won=92t be valid because everything will have expired already, = right? But CouchDB has no idea the index is time-sensitive, so it=92s = going to return you the old data anyway. You just cannot put = time-sensitive data into a map function. >>>=20 >>> Instead what you should be doing in the map is writing out the = expiration times of the documents. Then at query time you can see how = far in the future those are. >>>=20 >>> =97Jens >>=20