Closed liuxyCN closed 1 year ago
I had the same issue. Updating mongoose to the lastest available version fixed the issue
I am getting the same issue when using mongoose version 6.4.3, any help on this pls.
me too
Hey, guys!!
I saw this new implementation in mongoose 6+
in /lib/model.js:
function _checkContext(ctx, fnName) {
// Check context, because it is easy to mistakenly type
// `new Model.discriminator()` and get an incomprehensible error
if (ctx == null || ctx === global) {
throw new MongooseError('`Model.' + fnName + '()` cannot run without a ' +
'model as `this`. Make sure you are calling `MyModel.' + fnName + '()` ' +
'where `MyModel` is a Mongoose model.');
} else if (ctx[modelSymbol] == null) {
throw new MongooseError('`Model.' + fnName + '()` cannot run without a ' +
'model as `this`. Make sure you are not calling ' +
'`new Model.' + fnName + '()`');
}
}
my suspicions are in this _checkContext validator
modelSymbol in this context is "mongoose#Model" but its not finding on ctx
The new version (1.0.0) is heavily tested on Mongoose 5, 6, and 7. I didn't notice this problem.
mongoose 6 with 'overrideMethods: true' got error, pls help.
nodejs.MongooseError:
Model.findOne()
cannot run without a model asthis
. Make sure you are not callingnew Model.findOne()