Hey Jens!

Thanks a lot for that! 
Essentially, we are just creating a view now => which will be different for 
each user based on the same dataset.

I was trying to reduce the from & to somehow into 1 variable but was 
thinking in terms of the database structure rather than an indexed view 
which could be different for each user. 

Seems straightforward now & feels a bit stupid to not be able to figure it 
out earlier. 

Cheers
Archit

On Sunday, March 2, 2014 3:52:46 PM UTC+8, Jens Alfke wrote:
>
>
> On Mar 1, 2014, at 11:24 PM, archit agarwal <[email protected]<javascript:>> 
> wrote:
>
> Now I am confused about how to implement the reduce function so I get 
> messages in which => either from is X OR to is X 
> Any help on this would be really appreciated.
>
>
> That’s not the job of a reduce function. Reducing is like aggregation in 
> SQL — “SUM()”, ”MAX()”, “AVERAGE()”, etc.
>
> What you’re asking for in this query is a sub-range: “messages with X” for 
> some X. So what you want is a map function that emits keys that are ordered 
> by the *other person’s* identity, so you can then query for a specific 
> person.
>
> What I’d do is
>                 if([to isEqualToString:myuid])
>                     emit(@[from,timestamp],nil);
>                 else if([from isEqualToString:myuid])
>                     emit(@[to,timestamp],nil);
> Then query by
> query.startKey = @[other];
> query.endKey = @[other, @{}];
>
> —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/280347af-cb33-4916-a6bb-a89eae94bab9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to