rs / rest-layer

REST Layer, Go (golang) REST API framework
http://rest-layer.io
MIT License
1.26k stars 114 forks source link

Support for $not filter operation #273

Open tsetsoo opened 3 years ago

tsetsoo commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

$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 commented 3 years ago

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/