From user-return-22426-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Mon Oct 8 11:53:50 2012 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 1151597B0 for ; Mon, 8 Oct 2012 11:53:50 +0000 (UTC) Received: (qmail 54193 invoked by uid 500); 8 Oct 2012 11:53:48 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 53182 invoked by uid 500); 8 Oct 2012 11:53:41 -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 51599 invoked by uid 99); 8 Oct 2012 11:53:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Oct 2012 11:53:39 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [193.50.230.240] (HELO pluton.utt.fr) (193.50.230.240) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Oct 2012 11:53:31 +0000 Received: from smtp1.utt.fr (smtp1.utt.fr [193.50.230.122]) by pluton.utt.fr (8.13.1/8.13.1) with ESMTP id q98Br7Rs007450 for ; Mon, 8 Oct 2012 13:53:07 +0200 Received: from smtp1.utt.fr (smtp1.utt.fr [127.0.0.1]) by localhost (Postfix) with SMTP id 708101080002 for ; Mon, 8 Oct 2012 13:53:07 +0200 (CEST) Received: from wifi-personnels230.utt.fr (wifi-personnels230.utt.fr [10.19.1.230]) by smtp1.utt.fr (Postfix) with ESMTP id 622001080001 for ; Mon, 8 Oct 2012 13:53:02 +0200 (CEST) Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Apple Message framework v1278) Subject: Re: Sorting dates in CouchDB From: =?iso-8859-1?Q?Aur=E9lien_B=E9nel?= In-Reply-To: Date: Mon, 8 Oct 2012 13:53:02 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <5DEA0E58-A26C-43AF-97BC-66FC60BA744C@utt.fr> References: <6789B67E-1FCB-442F-95C5-30F89CEF1C94@utt.fr> To: user@couchdb.apache.org X-Mailer: Apple Mail (2.1278) X-Virus-Checked: Checked by ClamAV on apache.org Hi Carl, > OK so if I understand you correctly if I'm only querying using the = date part e.g. "2012-12-02" then it will work OK?=20 I'm not sure to understand, but if you use "key" instead of "startkey" = and "endkey", you will need the exact value you emitted. You have indeed several solutions: 1. emit the whole timestamp as a string, and query with startkey and = endkey using an endkey that is alphabetically greater than the last key = you want to grasp (for example : "2012-12-03" or even "2012-12-02Z" = instead of "2012-12-02") : ?startkey=3D"2012-10-02"&endkey=3D"2012-12-03" or=20 ?startkey=3D"2012-10-02"&endkey=3D"2012-12-02Z" {rows:[ {"key"=3D"2012-10-02T9:00:00+00:00", ...}, {"key"=3D"2012-12-01T10:00:00+00:00", ...}, {"key"=3D"2012-12-02T11:00:00+00:00", ...} ]} 2. emit as a string the part of the timestamp you want to query on, and = use startkey and endkey more naturally: ?startkey=3D"2012-10-02"&endkey=3D"2012-12-02" {rows:[ {"key"=3D"2012-10-02", ...}, {"key"=3D"2012-12-01", ...}, {"key"=3D"2012-12-02", ...} ]} 3. emit the whole timestamp as an array and query a part of it: ?startkey=3D[2012, 10, 2]&endkey=3D[2012, 12, 2, {}] {rows:[ {"key"=3D[2012, 10, 2, 9, 0], ...}, {"key"=3D[2012, 12, 1, 10, 0], ...}, {"key"=3D[2012, 12, 2, 11, 0], ...} ]} 4. emit the whole timestamp as an array and query a (reduced) group of = it: ?group_level=3D3&startkey=3D[2012, 10, 2]&endkey=3D[2012, 12, 2] {rows:[ {"key"=3D[2012, 10, 2], ...}, {"key"=3D[2012, 12, 1], ...}, {"key"=3D[2012, 12, 2], ...} ]} There's more than one way to do it. ;) Regards, Aur=E9lien =20=