feathersjs-ecosystem / feathers-mongodb

A mongodb service for feathers
MIT License
122 stars 42 forks source link

Not working find query with complex query on the _id field (ObjectId conversion) #222

Closed soullivaneuh closed 1 year ago

soullivaneuh commented 1 year ago

Steps to reproduce

Make a query like so:

const relatedUsers = await app.service('users').find({
  query: {
    _id: { $in: [
      'mongoid-1',
      'mongoid-2',
      'mongoid-3',
    ],
  },
  paginate: false,
});

Considering the referenced id are valid.

Expected behavior

Having 3 items as a result.

Actual behavior

Empty result.

Root cause

This is because the query values are not converted onto ObjectId as expected, the adapter only handle simple cases: https://github.com/feathersjs-ecosystem/feathers-mongodb/blob/c8e894cd433b39e5dc92ac824a983944768d25eb/lib/index.js#L120

I am currently working on a fix for that.

daffl commented 1 year ago

In v5 this has been addressed with the ObjectId keyword and converter.