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 3562E9BFC for ; Thu, 1 Mar 2012 19:34:11 +0000 (UTC) Received: (qmail 73964 invoked by uid 500); 1 Mar 2012 19:34:09 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 73891 invoked by uid 500); 1 Mar 2012 19:34:08 -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 73862 invoked by uid 99); 1 Mar 2012 19:34:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Mar 2012 19:34:08 +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 (athena.apache.org: transitioning domain of mcastonguay@justlexit.com does not designate 209.85.161.180 as permitted sender) Received: from [209.85.161.180] (HELO mail-gx0-f180.google.com) (209.85.161.180) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Mar 2012 19:34:02 +0000 Received: by gglu1 with SMTP id u1so530999ggl.11 for ; Thu, 01 Mar 2012 11:33:40 -0800 (PST) Received-SPF: pass (google.com: domain of mcastonguay@justlexit.com designates 10.236.197.98 as permitted sender) client-ip=10.236.197.98; Authentication-Results: mr.google.com; spf=pass (google.com: domain of mcastonguay@justlexit.com designates 10.236.197.98 as permitted sender) smtp.mail=mcastonguay@justlexit.com Received: from mr.google.com ([10.236.197.98]) by 10.236.197.98 with SMTP id s62mr9206036yhn.24.1330630420979 (num_hops = 1); Thu, 01 Mar 2012 11:33:40 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.197.98 with SMTP id s62mr7287614yhn.24.1330630420904; Thu, 01 Mar 2012 11:33:40 -0800 (PST) Received: by 10.147.152.16 with HTTP; Thu, 1 Mar 2012 11:33:40 -0800 (PST) X-Originating-IP: [70.83.120.42] In-Reply-To: <3D8B736F-2D61-4CCC-86EB-78F7DFB20DBD@sri.com> References: <3D8B736F-2D61-4CCC-86EB-78F7DFB20DBD@sri.com> Date: Thu, 1 Mar 2012 14:33:40 -0500 Message-ID: Subject: Re: starkey with multiple values not working as expected From: Mathieu Castonguay To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=20cf303f6d5290bbdd04ba33899d X-Gm-Message-State: ALoCoQmQt5hYqLBZYexwgk8Ke/1PDQHePUOOqqKKgyRqASt9HOBgGdJT52LNndF1CD/PLTJM1Y5/ X-Virus-Checked: Checked by ClamAV on apache.org --20cf303f6d5290bbdd04ba33899d Content-Type: text/plain; charset=ISO-8859-1 Thanks Jim, that did the trick. I hope that others will read your explanation and that it will save them time. I find that there is a great lack of resources on the web for couchdb, but thankfully there is this mailing list and helpful people like you who take the time to explain. Matt On Wed, Feb 29, 2012 at 7:25 PM, Jim Klo wrote: > actually, it's responding exactly as expected. > > you can't think of complex keys as a boolean "AND", but as a single value. > > so... > > ["2012-01-01T02:07:50.387+0000","97ee813bfe4dbbf80a48b018b20a08bb"] > > > is actually less than ALL your values because of CouchDB's collation rules. > > To explain this to others, I use the idea of turning the key into a > sentence.... typically i think of it as you have the last element grouped > by the the other elements from left to right. > > So you have "restaurantids grouped by timestamp" as your key, which means > for any given timestamp as a startkey/endkey, the last item in the key will > be a restuarantid... if you try rounding your timestamp to the nearest hour > in your example you'll see what I mean using your data... > > if you want to look up by restaurantid, order your keys from left to > right... [restaurantid, timestamp]... which will then order your view first > by restaurantid, then by timestamp... which gives you "timestamps grouped > by restaurantid" > > you'd then use > > > restaurant_orders_after_date?startkey=["97ee813bfe4dbbf80a48b018b20a08bb","2012-01-01T02:07:50.387+0000"]&endkey=["97ee813bfe4dbbf80a48b018b20a08bb",{}] > > > - Jim > > * > Jim Klo > Senior Software Engineer > Center for Software Engineering > SRI International > * > > On Feb 29, 2012, at 3:45 PM, Mathieu Castonguay wrote: > > Here is the view: > > "restaurant_orders_after_date": { > "map": "function(doc) { if(doc.restaurantId && > doc.timeOfLatestStatusChange && doc.status && (doc.status == 'ACCEPTED' || > doc.status == 'REJECTED')) { > emit([doc.timeOfLatestStatusChange,doc.restaurantId], doc._id)}}" > > Execution of the view: > > > restaurant_orders_after_date?startkey=["2012-01-01T02:07:50.387+0000","97ee813bfe4dbbf80a48b018b20a08bb"]&endkey=[{},"97ee813bfe4dbbf80a48b018b20a08bb"] > > > {"id":"6bb4423653c6d9138524c110cf0047fb","key":["2012-01-03T14:00:52.542+0000","f98ba9a518650a6c15c566fc6f03dc8d"],"value":"6bb4423653c6d9138524c110cf0047fb"}, > > {"id":"6bb4423653c6d9138524c110cf007276","key":["2012-01-03T17:34:49.565+0000","97ee813bfe4dbbf80a48b018b20a08bb"],"value":"6bb4423653c6d9138524c110cf007276"}, > > {"id":"6bb4423653c6d9138524c110cf006d26","key":["2012-01-03T17:36:31.222+0000","97ee813bfe4dbbf80a48b018b20a08bb"],"value":"6bb4423653c6d9138524c110cf006d26"}, > > {"id":"6bb4423653c6d9138524c110cf007c76","key":["2012-01-03T17:38:45.485+0000","97ee813bfe4dbbf80a48b018b20a08bb"],"value":"6bb4423653c6d9138524c110cf007c76"}, > > {"id":"6bb4423653c6d9138524c110cf006119","key":["2012-01-03T17:47:51.637+0000","29b384e85adcdf5b2085dadba5018d03"],"value":"6bb4423653c6d9138524c110cf006119"}, > > {"id":"6bb4423653c6d9138524c110cf005e51","key":["2012-01-03T18:00:35.185+0000","29b384e85adcdf5b2085dadba5018d03"],"value":"6bb4423653c6d9138524c110cf005e51"} > > It seems to completly ignore the second value which is the id of the > restaurant. I want all orders who's timeOfLatestStatusChange is greater > than the current time (in this case "2012-01-01T02:07:50.387+0000") and > who's restaurant id is a certain value(in this case > "97ee813bfe4dbbf80a48b018b20a08bb"). > > Can anyone explain to me why the second parameter seems ignored, I can mean > I can put "donkey" and it still does the same thing. > > Thank you, > > Matt > > > --20cf303f6d5290bbdd04ba33899d--