Couchbase lite: Applying postFilter best practices

16 views
Skip to first unread message

parvez....@decurtis.com

unread,
Jul 7, 2017, 10:53:15 AM7/7/17
to Couchbase Mobile
For a CBLView which is emitting a document with multiple key value pairs that represent a CBLModel instance, how we apply a postFilter (an NSPredicate) to be used to filter the rows as returned by query? Can we refer the field names directly in the predicate? I have seen examples where we use an indexing over 'value' like value0 == "some value". Can we instead do it like firstName == "some value"? Since referring a field name is much better and more appropriate term then simply indexing over key or value.

Thanks

Jens Alfke

unread,
Jul 7, 2017, 12:52:29 PM7/7/17
to mobile-c...@googlegroups.com

On Jul 7, 2017, at 7:53 AM, parvez....@decurtis.com wrote:

For a CBLView which is emitting a document with multiple key value pairs that represent a CBLModel instance, how we apply a postFilter (an NSPredicate) to be used to filter the rows as returned by query? Can we refer the field names directly in the predicate? I have seen examples where we use an indexing over 'value' like value0 == "some value". Can we instead do it like firstName == "some value"? Since referring a field name is much better and more appropriate term then simply indexing over key or value.

If you emit an NSDictionary as the value, you can access its values in the predicate as “value.x”. So for example, in the map function
emit(myKey, @{@“firstName”: doc[“first_name”]});
and then in your predicate you can refer to “value.firstName”.

—Jens
Reply all
Reply to author
Forward
0 new messages