Skip to content

Commit

Permalink
fix(schema): throw more helpful error when defining a document array …
Browse files Browse the repository at this point in the history
…using a schema from a different copy of the Mongoose module

Fix #10453
  • Loading branch information
vkarpov15 committed Aug 9, 2021
1 parent cdd4116 commit ee5b391
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -933,11 +933,21 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
: type[0];

if (cast && cast.instanceOfSchema) {
if (!(cast instanceof Schema)) {
throw new TypeError('Schema for array path `' + path +
'` is from a different copy of the Mongoose module. Please make sure you\'re using the same version ' +
'of Mongoose everywhere with `npm list mongoose`.');
}
return new MongooseTypes.DocumentArray(path, cast, obj);
}
if (cast &&
cast[options.typeKey] &&
cast[options.typeKey].instanceOfSchema) {
if (!(cast[options.typeKey] instanceof Schema)) {
throw new TypeError('Schema for array path `' + path +
'` is from a different copy of the Mongoose module. Please make sure you\'re using the same version ' +
'of Mongoose everywhere with `npm list mongoose`.');
}
return new MongooseTypes.DocumentArray(path, cast[options.typeKey], obj, cast);
}

Expand Down

0 comments on commit ee5b391

Please sign in to comment.