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 2E54973E1 for ; Fri, 5 Aug 2011 23:54:21 +0000 (UTC) Received: (qmail 8309 invoked by uid 500); 5 Aug 2011 23:54:19 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 8240 invoked by uid 500); 5 Aug 2011 23:54:18 -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 8228 invoked by uid 99); 5 Aug 2011 23:54:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Aug 2011 23:54:18 +0000 X-ASF-Spam-Status: No, hits=1.8 required=5.0 tests=FREEMAIL_FROM,FREEMAIL_REPLY,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of zachary.zolton@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; Fri, 05 Aug 2011 23:54:13 +0000 Received: by wyj26 with SMTP id 26so1967769wyj.11 for ; Fri, 05 Aug 2011 16:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=YDfWLWbTfW7mA3NhrJGAEFZTBoNVuwj6x/8SJW5ID+w=; b=kp56Uk2rY54QpwtEcsm//j+7HaBWx+R81hZO+6ktC7fW00V8dhj3t9HwpUCWNRWLq5 jlFbE1I760JdwEyjAUpNVO8K1+p7vdVmVqbOJFCW40ciuJ8kyPhN0TLwdxATOan37YG3 +6uJCvyEvGlSihnnRHg5HkbYOmZnCyMsq5CJQ= Received: by 10.227.42.131 with SMTP id s3mr2360414wbe.104.1312588432204; Fri, 05 Aug 2011 16:53:52 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.42.205 with HTTP; Fri, 5 Aug 2011 16:53:32 -0700 (PDT) In-Reply-To: References: From: Zachary Zolton Date: Fri, 5 Aug 2011 18:53:32 -0500 Message-ID: Subject: Re: View collation by one key and sorting by another key To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Matthew, Your welcome. Also, flipping the keys around might be another interesting index--for seeing counts of all itemIds for a particular day. Cheers, Zach On Fri, Aug 5, 2011 at 6:10 PM, Matthew Slade wrote: > Hi Zach (and Randall) > > Thanks. I totally see the value now in splitting the date into it's > components to get a controlled grain for grouping with the itemId as the > first key. :) > > Thanks for all your help. > > Matthew > > On Sat, Aug 6, 2011 at 12:54 AM, Zachary Zolton wrote: > >> If you want oranges sold over time, try this view: >> >> map: function(doc) { >> =A0var dateOfPurchase =3D trimOffTimePart(doc.dateOfPurchase); >> =A0emit([doc.itemId, dateOfPurchase], null); >> } >> >> reduce: _count >> >> Now, query to get the counts: >> >> http://couch/db/_design/app/_view/items-sold-by-date?group=3Dtrue&startk= ey=3D[ >> "oranges"]&endkey=3D["oranges",{}] >> >> (You'll have to URL encode those keys, too...) >> >> That should result in a row with a count of oranges sold for each day. >> More like what you were looking for? (^_^ >> >> --Zach >> >> >> On Fri, Aug 5, 2011 at 5:34 PM, Matthew Slade >> wrote: >> > Hi Randall >> > >> > Thanks, I'm aware of the ability to split out the date into multiple k= eys >> > for easier collation. However that's not really the issue here. My >> problem >> > is with the additional level of sorting that might be required to make >> the >> > reduced data meaningful. ie I want to know only about oranges and not >> other >> > fruit in my particular date time collation. >> > >> > Matthew >> > >> > On Sat, Aug 6, 2011 at 12:19 AM, Randall Leeds > >wrote: >> > >> >> On Fri, Aug 5, 2011 at 15:00, Matthew Slade >> >> wrote: >> >> > Hi Zach (and everyone else) >> >> > >> >> > Thanks for the info. Unfortunately my game is already big and the >> >> proposed >> >> > solution wouldn't really be suitable although _lists seem interesti= ng >> and >> >> > I'll definitely investigate them. I do find this quite a limitation= to >> >> > couchdb especially when one is working a lot with dated documents. >> >> > >> >> > Another question I have in a similar vein: >> >> > >> >> > Given a set of documents being created for transaction for the >> purchase >> >> of >> >> > fruit for example. >> >> > >> >> > * { >> >> > "_id":"uniqueOrderId", >> >> > "dateOfPurchase": "2011-07-06T10:24:52", >> >> > "itemId": "oranges" >> >> > }* >> >> > >> >> > Could one collate the view entries by the date and then reduce base= d >> off >> >> of >> >> > part of the value. ie How could I easily answer the question "*How >> many >> >> > oranges were sold on Wednesday*?" efficiently with potentially huge >> >> numbers >> >> > of transaction documents in my database. >> >> >> >> You should separate the key you emit into an array of the date pieces >> >> like [YYYY, MM, DD, ...]. >> >> Then you can use ?group_level=3DX with your reduce query to get hourl= y, >> >> daily, monthly, etc summaries. >> >> >> >> -Randall >> > >> >