Thanks a lot Jens. I have read all the docs and now I understand it but I definitely need some practice to learn how to put all this theory to work. Thanks for your help.
--- Sébastien Arbogast http://sebastien-arbogast.com 2014-07-14 1:22 GMT+02:00 Jens Alfke <[email protected]>: > > On Jul 13, 2014, at 1:59 PM, Sebastien ARBOGAST < > [email protected]> wrote: > > With this I think I can filter my documents to get only open sessions, but > how should I proceed to get only the one with the biggest start date for > each owner in my query? > > > You probably want a view whose primary key is owner (because you want to > query for a specific owner) and secondary key is date (because you want to > sort by date.) The way you do that is by emitting a key that’s an array of > the form @[owner, date]. That way you can query for all the rows with a > specific owner, by specifying a key range, and the rows will end up sorted > by date. If you only want the maximum date, then you just need to fetch the > last row. > > So in your query you set > descending = true // because you want to start with the max date > limit = 1 // because you only want the row with the max date > startKey = @[owner, @{}] // i.e. the last/max row with the given owner > endKey = @[owner] // i.e. the first row with the given owner > > The @{} in the startKey is an idiom for “infinity”, because by the sorting > rules a dictionary sorts after anything else. It’s commonly used as a > placeholder when setting a range in a view that has array-based keys. > > The docs for views > <http://developer.couchbase.com/mobile/develop/guides/couchbase-lite/native-api/view/index.html#keys> > and queries > <http://developer.couchbase.com/mobile/develop/guides/couchbase-lite/native-api/query/index.html#key-ranges> > cover > all of these concepts. > > —Jens > > -- > You received this message because you are subscribed to the Google Groups > "Couchbase Mobile" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/mobile-couchbase/13D1BD6E-1373-48AA-AD26-E484BF676B49%40couchbase.com > <https://groups.google.com/d/msgid/mobile-couchbase/13D1BD6E-1373-48AA-AD26-E484BF676B49%40couchbase.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/CAG1DMa8McrGUi1hT7sk0f3pCrG%2B8wQe7iJp2KucOOO1PGkV2_g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
