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

Support for $not filter operation #273

Open
tsetsoo opened this issue Sep 23, 2021 · 4 comments
Open

Support for $not filter operation #273

tsetsoo opened this issue Sep 23, 2021 · 4 comments

Comments

@tsetsoo
Copy link
Contributor

tsetsoo commented Sep 23, 2021

Hello,

I am using Mongo DB as storage, but not rest-layer-mongo.

I want to implement Contains and Does Not Contain filters. For Contains I can use the $regex operation. However, for Does Not Contain I cannot use $regex, since Go does not support lookarounds and regexes are currently validated with Go's standard library. Using $not seems to me like the obvious alternative.

Per #272 I know that there is not active development on this library, so this issue is to ask if a reason exist for this feature to be missing. If there is no such reason, I will implement it myself (including support for $not-ing a regex and $not-ing a whole expression).
#237 looks like an appropriate PR to model after

@smyrman
Copy link
Collaborator

smyrman commented Sep 23, 2021

I don't see any reason why this feature could not be added. Please do feel free to create a PR for it.

I am using Mongo DB as storage, but not rest-layer-mongo.

Want to share what you are using? Is it in a state in which other could use it, or it's written more specifically for the purpose at hand?

@tsetsoo
Copy link
Contributor Author

tsetsoo commented Sep 23, 2021

I've opened #274 with the initial implementation of the $not operator with regex, functioning as an opposite to $regex.
I'll add a second PR with the implementation of $not-ing a whole expression since that seems a bit trickier

Want to share what you are using? Is it in a state in which other could use it, or it's written more specifically for the purpose at hand?

Unfortunately, it's written for the purpose at hand. One of the main blocker would have been the support for mgo over mongo.
Regardless, I'll open a PR in rest-layer-mongo after I'm finished here, to add support for $not

@smyrman
Copy link
Collaborator

smyrman commented Sep 23, 2021

$not-ing a whole expression since that seems a b

To be honest, I am not sure how useful it is to be able to not the whole expression. The docs does state that
{price: {$not: {$gt: 12}}} is not equivalent to{price: {$lte: 12}}, since the prior would match any documents where the price is not set while the latter would not. If this is really the query you want, you could just do {$or: [{price: {$lte: 12}}, {price:{$exists: false}]}, which would be more explicit anyways.

@smyrman
Copy link
Collaborator

smyrman commented Sep 23, 2021

So at least I am not against only implement $not as an oposite to $regex. An views from you @rs?

For reference: https://docs.mongodb.com/manual/reference/operator/query/not/

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