Skip to content

Commit

Permalink
fix(schema): allow declaring ObjectId array with `{ type: 'ObjectID' …
Browse files Browse the repository at this point in the history
…}`, last 'D' case insensitive

Fix #8034
  • Loading branch information
vkarpov15 committed Aug 6, 2019
1 parent bc71f25 commit f47e936
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,15 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
? type
: type.schemaName || utils.getFunctionName(type);

if (!(name in MongooseTypes)) {
name = name.charAt(0).toUpperCase() + name.substring(1)

if (!MongooseTypes.hasOwnProperty(name)) {
throw new TypeError('Invalid schema configuration: ' +
`\`${name}\` is not a valid type within the array \`${path}\`.` +
'See http://bit.ly/mongoose-schematypes for a list of valid schema types.');
}

cast = MongooseTypes[name];
}

return new MongooseTypes.Array(path, cast || MongooseTypes.Mixed, obj, options);
Expand Down
1 change: 1 addition & 0 deletions lib/schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ exports.Map = require('./map');
exports.Oid = exports.ObjectId;
exports.Object = exports.Mixed;
exports.Bool = exports.Boolean;
exports.ObjectID = exports.ObjectId;

0 comments on commit f47e936

Please sign in to comment.