feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.97k stars 742 forks source link

is operator option deprecated really? #3407

Closed fxpoet closed 5 months ago

fxpoet commented 5 months ago

Steps to reproduce

query = { title: { $regex: 'keyword' } }
service.find({ query })

I got error : Invalid query parameter title $regex

I thought this was an error that occurred in QueryValidator on service hooks, but it was not. I was able to find out that it was an error that occurred in validateQueryProperty in adapter-commons.

I resolved it append operators:['$regex'] to service class constructor options.

svc = new MyService({ operators: ['$regex'] }) 
app.use('myservice', svc)

but, there was a difference from the documentions. (https://feathersjs.com/api/databases/common.html#options)

operators {string[]} (optional, deprecated) - A list of additional non-standard query parameters to allow (e.g [ '$regex' ]). Not necessary when using a [query schema](https://feathersjs.com/api/schema/validators.html#validatequery)

"deprecated and not necessary". but the operator option was required.

I read source code of @feathersjs/mongodb version 5.0.21 and noticed that the .find method still utilizes the sanitizeQuery function.

Expected behavior

export const customersQuerySchema = Type.Intersect([
    querySyntax(customersQueryProperties, {
        content: { $regex: Type.String() }, 
        title:   { $regex: Type.String() },
    }),
    Type.Object({})
], { additionalProperties: false })

I believed that using queryValidator in the hooks would make that operator option unnecessary, but it still seems to be needed.

I think this feathers framework is really excellent and I use it as my main framework. therefore, I always feel grateful to the development team.

I'm posting this issue so other developers can find it when they search for similar problems.