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

Explicit $eq in filter passes whole predicate to Validate(Query) #254

Open
mishak87 opened this issue Aug 3, 2019 · 3 comments
Open

Explicit $eq in filter passes whole predicate to Validate(Query) #254

mishak87 opened this issue Aug 3, 2019 · 3 comments

Comments

@mishak87
Copy link
Contributor

mishak87 commented Aug 3, 2019

I have encountered confusing behavior that does not lead to error.

For example ?filter={field:{$eq:"value"}} will pass map[string]interface{}{"$eq": "value"} instead of "value" to Validate functions. Proper form ?filter={field:"value"} works as expected passing "value". I assume this behavior is caused because query.Equal is a default predicate operator.

@smyrman
Copy link
Collaborator

smyrman commented Aug 4, 2019

"$eq" is not recognized as an operator by rest-layer. All operators currently handed can be found here:

@mishak87
Copy link
Contributor Author

mishak87 commented Aug 5, 2019

MongoDB supports both variants I think compatibility is a strong argument for adding it.

It will be a breaking change to support it.

It would make more convenient playing with filters because all other filters require wrapping in object {<op>:<value>}. Counting closing braces gets bit annoying after a long day.

@smyrman
Copy link
Collaborator

smyrman commented Aug 5, 2019

rest-layer only aims to support/allow a sub-set of the MongoDB query syntax, but in this case I agree. We can just add it.

Unfortunately the amount of time I have found to contribute to rest-layer have been quite limited. Are you open to attempt a PR for it? Otherwise I will try to fix it eventually.

On the note of operator parsing, I just want to mention that there are more problems to be aware of... rest-layer only allows one operator within a given dict. E.g. {$lt: 4, $gt:1} would be legal in MongoDB, but not understood by rest-layer. In rest-layer we would instead need to wrap it via an explicit and: {"$and":[{$lt: 4},{$gt:1}]}. Fixing this is a bigger change, so we will leave it out-of-scope.

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

No branches or pull requests

2 participants