I'm a total newbie with NoSQL DBs in general, and with Couchbase in 
particular. My main document type is a Session type. A Session document has 
a startDate, an endDate and an owner field.
Several sessions can be owned by the same user. A session is closed if it 
has an endDate. On one given device, a given user can only open a Session 
if it doesn't already have one open. But they can open a session on another 
device, which means I can have several open sessions in my database for any 
given owner. I want to retrieve the most recently open session for a given 
owner. I'm pretty sure it can be done with a clever map/reduce view, but 
I'm sill confused about how it works. Here is what I started doing in 
Objective-C:

[[database viewNamed:@"openByOwner"] setMapBlock:^(NSDictionary *doc, 
CBLMapEmitBlock emit) {    if([doc[@"type"] isEqualToString:@"session"] && 
doc[@"endDate"] == nil){        emit(doc[@"owner"], doc);    }} 
reduceBlock:^id(NSArray *keys, NSArray *values, BOOL rereduce) {    return 
nil;} version:@"1.0"];


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 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/cbe87696-8b0e-4b59-9736-fc0c8d2e26d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to