Filter CBLView by keys

60 views
Skip to first unread message

Eduardo Scoz

unread,
Feb 23, 2014, 4:17:42 PM2/23/14
to mobile-c...@googlegroups.com
Hey guys, great work on CBL!

I have a view with a map/reduce function that returns rows like:

KEY: @[@"A", @"Car", @"2"], VALUE: Something
KEY: @[@"A", @"Car", @"3"], VALUE: Something
KEY: @[@"A", @"Dog", @"3"], VALUE: Something
KEY: @[@"B", @"Dog", @"4"], VALUE: Something

How can I set up the startkey/endkey/key so that the view only returns rows with keys starting with @[@"A", @"Car"] ? 

Is there any way to do that, or would I have to have a different reduce function for that?

Eduardo Scoz

unread,
Feb 23, 2014, 4:21:30 PM2/23/14
to mobile-c...@googlegroups.com
I guess the question really is: 

is there any way to filter them out before the reduce function runs, or is the proper approach to reduce the view again, and pass the values I would like from the key to the value?

Jens Alfke

unread,
Feb 23, 2014, 5:35:58 PM2/23/14
to mobile-c...@googlegroups.com

On Feb 23, 2014, at 1:17 PM, Eduardo Scoz <eduar...@gmail.com> wrote:

How can I set up the startkey/endkey/key so that the view only returns rows with keys starting with @[@"A", @"Car"] ? 

view.startKey = @[@“A”, @“Car”];
view.endKey = @[@“A”, @“Car”, @{}];

The trick is that an empty dictionary sorts after any non-dictionary value, making it useful to use at the end of a range.

—Jens

Eduardo Scoz

unread,
Feb 23, 2014, 10:00:57 PM2/23/14
to mobile-c...@googlegroups.com
oh nice trick, I'll give it at try!
Reply all
Reply to author
Forward
0 new messages