CampbellSoftwareSolutions / mongoose-id-validator

Mongoose plug in to validate ObjectID references point to valid existing documents.
Other
47 stars 26 forks source link

Plugin not working with mongoose ^4.7.7 via trailpack-mongoose #21

Open ricick opened 6 years ago

ricick commented 6 years ago

Hey i'm building a trailsjs based application with a mongo db managed via the trailpack-mongoose addon.

The current release of this addon uses mongoose ^4.7.7.

When i install this plugin in one of my trails models like so:

...
class MyModel extends Model {
  static config() {
    let config  = {}
    config.onSchema = (app, schema)=>{
      schema.plugin(idvalidator);
    }
    return config
  }
  ...

any calls to save a document hang.

let item = new MyModel(object);
item.save().then(neverGetsCalled)

I've been through the internals of the plugin and mongoose. and it seems to be an issue with the exec method in mongoose/lib/query.js on line 3087 that is called by the executeQuery method of this library . If the callback is passed as a second parameter to exec, as this library does, it is called by an internal promise resolve call, but the promise never resolves. I've tried changing this library to use a promise instead of passing a callback, but again it never resolves.

Any help would be greatly appreciated. I find it hard to imagine that this is an unknown mongoose issue with such an important method as query.exec