Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$or and $and operators in custom Filters #471

Open
AZWN opened this issue Aug 23, 2017 · 2 comments
Open

$or and $and operators in custom Filters #471

AZWN opened this issue Aug 23, 2017 · 2 comments

Comments

@AZWN
Copy link

AZWN commented Aug 23, 2017

The Mongo operators $or and $and do not work when set from a custom filter.

Example code:

var selectedValues = $('#multipleSelect').val(); // ["val1", "val2"]
template.filter.set({ $or: selectedValues });

Resulting stacktrace:

Exception in template helper: Error: Unrecognized operator: $or
    at http://localhost:3000/packages/minimongo.js?hash=68d94baf766fd5bcc86fc44a6758779727eb60f8:1535:13
    at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?hash=cde485f60699ff9aced3305f70189e39c665183c:157:22)
    at operatorBranchedMatcher (http://localhost:3000/packages/minimongo.js?hash=68d94baf766fd5bcc86fc44a6758779727eb60f8:1519:5)
    at compileValueSelector (http://localhost:3000/packages/minimongo.js?hash=68d94baf766fd5bcc86fc44a6758779727eb60f8:1431:12)
    at http://localhost:3000/packages/minimongo.js?hash=68d94baf766fd5bcc86fc44a6758779727eb60f8:1411:26
    at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?hash=cde485f60699ff9aced3305f70189e39c665183c:157:22)
    at compileDocumentSelector (http://localhost:3000/packages/minimongo.js?hash=68d94baf766fd5bcc86fc44a6758779727eb60f8:1398:5)
    at http://localhost:3000/packages/minimongo.js?hash=68d94baf766fd5bcc86fc44a6758779727eb60f8:1546:12
    at Array.map (<anonymous>)
    at Function._.map._.collect (http://localhost:3000/packages/underscore.js?hash=cde485f60699ff9aced3305f70189e39c665183c:167:56)

Without looking at the code I can imagine that the mongo query generated by the package looks like { myFilterField: { $or: selectedValues }, while you would expect $or: [ { myFilterField: 'val1' }, myFilterField: 'val2' }].

This might be related to #444

@aslagle
Copy link
Owner

aslagle commented Aug 27, 2017

You're right, $and and $or don't work inside filters. As a workaround you can create multiple filters and set the filterOperator argument to reactiveTable to $and or $or. It won't handle nested ands or ors, but I think it's enough for most use cases.

@AZWN
Copy link
Author

AZWN commented Aug 28, 2017

In our case, we had defined custom filter using a multiple select($or), among other filters($and). That case is indeed not possible now. I solved it by joining the selected values with a |, and passing that using the $regex query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants