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 20826E628 for ; Fri, 4 Jan 2013 10:38:58 +0000 (UTC) Received: (qmail 45799 invoked by uid 500); 4 Jan 2013 10:38:56 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 45758 invoked by uid 500); 4 Jan 2013 10:38: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 45713 invoked by uid 99); 4 Jan 2013 10:38:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Jan 2013 10:38:53 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of simon@cloudant.com designates 209.85.212.181 as permitted sender) Received: from [209.85.212.181] (HELO mail-wi0-f181.google.com) (209.85.212.181) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Jan 2013 10:38:45 +0000 Received: by mail-wi0-f181.google.com with SMTP id hm9so9141605wib.2 for ; Fri, 04 Jan 2013 02:38:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:date:from:to:message-id:in-reply-to:references:subject :x-mailer:mime-version:content-type:content-transfer-encoding :content-disposition:x-gm-message-state; bh=Ooa38GJwAbx7DWOpm+6Q94CZ/vLh6EOk1ggx1vtVImM=; b=UxeZI2c5IzSdsmW4ClpIkcqJ8+mPYyOh4xYsgbiV1DXnfP4hzbzBC664LDYZqd6oYK 8kEdkX/k6cYSzLlPq2q7MQ2+vlh1DmWQACPRFbtjuYmkrFYiJH0y8LLqpkdvjxDNjFni 575Sea/FCwPddfb8b7qDC4BKWWR4JOm+9KLXZQj9mVUMkZ1bGRpWN2Ri3mjhvK5RjzZd DlBtEogU6r+w3Y0UxUShxUnr3k+e75y1LWv0cKRPO9fkh8yUEogoaI930hX48ws+VwTc 5DIi8jCzOY/3fF7Z3AGvNf4sXQlaX6vMERF6iNwldYrGhKYa/14v2AZCWCFzajtV63Ie 4RzA== X-Received: by 10.180.99.129 with SMTP id eq1mr72918179wib.30.1357295904031; Fri, 04 Jan 2013 02:38:24 -0800 (PST) Received: from [192.168.1.74] (93-97-111-13.zone5.bethere.co.uk. [93.97.111.13]) by mx.google.com with ESMTPS id s16sm1166105wii.0.2013.01.04.02.38.22 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 04 Jan 2013 02:38:23 -0800 (PST) Date: Fri, 4 Jan 2013 10:38:20 +0000 From: Simon Metson To: user@couchdb.apache.org Message-ID: <65E0D86D4D7947D5A7E19D42FBB7547C@cloudant.com> In-Reply-To: References: Subject: Re: view ordered by DateTime X-Mailer: sparrow 1.6.4 (build 1178) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Gm-Message-State: ALoCoQkH/vUqSkm6/r39+NEJhYm62Oxd9ubbhOwSRaoHLaUiBE2oBqUOlVRs8sXQqLZSW24xdDq0 X-Virus-Checked: Checked by ClamAV on apache.org Hey, =20 You need to either covert the date into a number (epoch seconds or simila= r) or make the date stamp into a date object and emit the pieces, e.g.: function(doc) =7B date =3D new Date(Date.parse(doc.date)); emit(=5Bdate.getUTC=46ullYear(), date.getUTCMonth(), date.getUTCDay(), = date.getUTCHours(), date.getUTCMinutes()=5D, doc.text); =7D The advantage of doing the date key as a list is you can have a reduce (l= ike =5Fcount) and see number of documents at the different group levels (= year, month, day=E2=80=A6) Cheers Simon On =46riday, 4 January 2013 at 10:30, ishi soichi wrote: > couchdb latest > python 2.7 > ruby 1.9.3 > =20 > I have a database obtained from Twitter. > Each tweet contains the information about when it's created, namely, > created=5Fat. > =20 > The problem is if I try to view them with the function > =20 > function(doc) =7B > if (doc=5B'created=5Fat'=5D =21=3D null) =7B > emit(doc=5B'created=5Fat'=5D, doc=5B'text'=5D); > =7D > =7D > =20 > the tweets are ordered ALPHABETICALLY, not by datetime. > =20 > This is because the data is stored in couchdb in the form of String rat= her > than DateTime object. > =20 > How can I order the outputs by DateTime=3F > =20 > I can program in JavaScript, Ruby(couchrest), and Python, I appreciate > concrete example using any of these languages. > =20 > soichi =20