Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Service adapter operators property marked as deprecated while still needed to use MongoDB specific operators starting with $ #3431

Open
Psycholisk opened this issue Feb 22, 2024 · 4 comments

Comments

@Psycholisk
Copy link

Steps 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

  • Apple M2

Module versions (especially the part that's not working):

  • Feathersjs ^5.0.11
  • Mongodb ^6.1.0

NodeJS version:

  • Node 18.16.0

Operating System:

  • MacOS 14.1.2 (23B92)
@seansps
Copy link

seansps commented 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
Copy link

junit38 commented 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
Copy link

seansps commented 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
Copy link

junit38 commented Dec 10, 2024 via email

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants