couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mathieu Castonguay <mcastong...@justlexit.com>
Subject Re: starkey with multiple values not working as expected
Date Thu, 01 Mar 2012 19:33:40 GMT
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 <jim.klo@sri.com> 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
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message