GeezerVison is showing github.com — Service adapter `operators` property marked as deprecated while still needed to use MongoDB specific operators starting with `$` · Issue #3431 · feathersjs/feathers
Service adapter operators property marked as deprecated while still needed to use MongoDB specific operators starting with $ #3431DescriptionSteps to reproduce
- Use the
@feathersjs/mongodb adapter as a datasesource adapter for your project
- Add the operator to the queryable fields in the TypeBox querySchema as follows
export const tagQuerySchema = Type.Intersect(
[
querySyntax(tagQueryProperties, {
title: {
$regex: Type.Any()
}
}),
// Add additional query properties here
Type.Object({}, { additionalProperties: false })
],
{ additionalProperties: false }
)
- Query the collection with the following query
app.service('tags').find({
query: {
title: {
$regex: /(?:)/i
}
}
})
Expected behavior
As per the latest docs, specifying the operator in the querySchema is sufficient to allow custom operators call, without the need to add the option operators: ['$regex'] to the service adapter options.
The query should return the documents that have a title that match this regex expression.
Actual behavior
Instead we get this error error: BadRequest: Invalid query parameter $regex.
Only when I add the operators option (which is marked as deprecated) it works fine.
System configuration
Module versions (especially the part that's not working):
- Feathersjs ^5.0.11
- Mongodb ^6.1.0
NodeJS version:
Operating System:
Activityseansps commented on Mar 13, 2024 I am running into this same issue, is there a workaround?
Edit:
I see, I was able to get it to work adding: operators: ['$regex', '$options'], junit38 commented on Dec 10, 2024
I am running into this same issue, is there a workaround?
Edit: I see, I was able to get it to work adding: operators: ['$regex', '$options'],
Where do you added those operators ? seansps commented on Dec 10, 2024
I am running into this same issue, is there a workaround?
Edit: I see, I was able to get it to work adding: operators: ['$regex', '$options'],
Where do you added those operators ?
If you're using TS and generating services, you'll have a .class.ts file like I do, and I added it like so:
export const getOptions = (app: Application): MongoDBAdapterOptions => {
return {
paginate: app.get('paginate'),
operators: ['$regex', '$options'],
Model: app
.get('mongodbClient')
.then((db) => db.collection('journals'))
.then((collection) => {
collection.createIndex({ moduleId: 1 })
return collection
}),
multi: ['remove']
}
junit38 commented on Dec 10, 2024 Found it thanks !
…
On Tue, Dec 10, 2024, 4:22 PM Sean Schnell ***@***.***> wrote:
I am running into this same issue, is there a workaround?
Edit: I see, I was able to get it to work adding: operators: ['$regex',
'$options'],
Where do you added those operators ?
If you're using TS and generating services, you'll have a .class.ts file
like I do, and I added it like so:
export const getOptions = (app: Application): MongoDBAdapterOptions => {
return {
paginate: app.get('paginate'),
operators: ['$regex', '$options'],
Model: app
.get('mongodbClient')
.then((db) => db.collection('journals'))
.then((collection) => {
collection.createIndex({ moduleId: 1 })
return collection
}),
multi: ['remove']
}
—
Reply to this email directly, view it on GitHub
< #3431 (comment)>,
or unsubscribe
< https://github.com/notifications/unsubscribe-auth/ABUSN4GOVV7JHXSPPQAHTWL2E4BMPAVCNFSM6AAAAABTLDQNCOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMZSGAYTQNJXHE>
.
You are receiving this because you commented.Message ID:
***@***.***>
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|