Advanced Filtering
Is there any way to filter with argument basic processing on the q.field() attribute? I am wary of using a searchIndex because I only want to return an item if it fits the criteria exactly. An example would be this:
3 Replies
in this case, I would just iterate over the raw results and use something like
_.filter
or whatever. query.filter is just a JavaScript userspace process anyway. Unlike .withIndex
, it's not utilizing some database-specific capability for optimization. so you can just write the loop yourself and do arbitrarily powerful comparisons
since you're calling .first()
you can just short-circuit and exit the loop when you find a matching recordI don't think we have many examples in docs, so the syntax for filtering in javascript and exiting early would be:
And to add one more option to the pile, I often see things like this stored as a second field with the lowercase version so you can do exact lookups. Eg storing the email as lowercase but a displayEmail with the casing the user provided