From user-return-19796-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Mon Feb 13 18:28:22 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 E29D19276 for ; Mon, 13 Feb 2012 18:28:22 +0000 (UTC) Received: (qmail 97293 invoked by uid 500); 13 Feb 2012 18:28:21 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 97219 invoked by uid 500); 13 Feb 2012 18:28:20 -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 97211 invoked by uid 99); 13 Feb 2012 18:28:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Feb 2012 18:28:20 +0000 X-ASF-Spam-Status: No, hits=2.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_SOFTFAIL X-Spam-Check-By: apache.org Received-SPF: softfail (nike.apache.org: transitioning domain of mcastonguay@justlexit.com does not designate 209.85.213.52 as permitted sender) Received: from [209.85.213.52] (HELO mail-yw0-f52.google.com) (209.85.213.52) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Feb 2012 18:28:13 +0000 Received: by yhgm50 with SMTP id m50so3214702yhg.11 for ; Mon, 13 Feb 2012 10:27:52 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.124.105 with SMTP id w69mr22132992yhh.31.1329157670431; Mon, 13 Feb 2012 10:27:50 -0800 (PST) Received: by 10.146.241.13 with HTTP; Mon, 13 Feb 2012 10:27:50 -0800 (PST) X-Originating-IP: [70.83.120.42] In-Reply-To: <4643A725-CF8E-4726-85D2-E452A671B2AB@sri.com> References: <4643A725-CF8E-4726-85D2-E452A671B2AB@sri.com> Date: Mon, 13 Feb 2012 13:27:50 -0500 Message-ID: Subject: Re: Question about multiple keys with ranges From: Mathieu Castonguay To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=20cf3010eb69cbeb0a04b8dca2ba X-Gm-Message-State: ALoCoQlhTCHAhKfIGqO1H1coqsQf3AoLkuOFPoAFRs5aQj0C398SlFWoxbizbAKym+jdC2A3HVqa X-Virus-Checked: Checked by ClamAV on apache.org --20cf3010eb69cbeb0a04b8dca2ba Content-Type: text/plain; charset=ISO-8859-1 I tried reversing the keys with no luck. I still get timestamps that are in the past (before the startKey). On Sat, Feb 11, 2012 at 6:37 PM, James Klo wrote: > Reverse the key. [userid, time] > > CouchDB is all about understanding collation. Basically views are > sorted/grouped from left to right alphanumeric. See > http://wiki.apache.org/couchdb/View_collation for the finer details as > there are more rules than the basics I mention. > > so the reversal sorts the view by userid first, then date as string. > Instead of sorting by dates then userids. > > You do it this way because you know the exact userid, but not the exact > date. If you knew the exact date, but not the userid, what you have > currently would be better. > > - Jim > > > Sent from my iPad > > On Feb 11, 2012, at 1:54 PM, "Mathieu Castonguay" < > mcastonguay@justlexit.com> wrote: > > > I have a simple document named Order structure with the fields id, name, > > userId and timeScheduled. > > > > What I would like to do is create a view where I can find the > > document.idfor those who's userId is some value and timeScheduledis > > after a given date. > > > > My view: > > > > "by_users_after_time": { > > "map": "function(doc) { if (doc.userId && doc.timeScheduled) { > > emit([doc.timeScheduled, doc.userId], doc._id); }}" > > } > > > > If I do > > > localhost:5984/orders/_design/Order/_view/by_users_after_time?startKey="[2012-01-01T11:40:52.280Z,f98ba9a518650a6c15c566fc6f00c157]" > > I get every result back. Is there a way to access key[1] to do an if > > doc.userId == key[1] or something along those lines and simply emit on > the > > time? > > > > This would be the SQL equivalent of select id from Order where userId = > > "f98ba9a518650a6c15c566fc6f00c157" and timeScheduled > > > 2012-01-01T11:40:52.280Z; > > > > I did quite a few Google searches but I can't seem to find a good > tutorial > > on working with multiple keys. It's also possible that my approach is > > entirely flawed so any guidance would be appreciated. > > > > Thank you, > > > > Matt > --20cf3010eb69cbeb0a04b8dca2ba--