Automattic/mongoose · error
MONGOOSE
MONGOOSE
Error message
mongoose: To create a new ObjectId please try `Mongoose.Types.ObjectId` instead of using `Mongoose.Schema.Types.ObjectId`. Set the `suppressWarning` option if you're trying to create a hex char path in your schema.
What it means
Error "mongoose: To create a new ObjectId please try `Mongoose.Types.ObjectId` instead of using `Mongoose.Schema.Types.ObjectId`. Set the `suppressWarning` option if you're trying to create a hex char path in your schema." thrown in Automattic/mongoose.
Source
Thrown at lib/schema/objectId.js:33
const CastError = SchemaType.CastError;
let Document;
/**
* ObjectId SchemaType constructor.
*
* @param {string} key
* @param {object} options
* @param {object} schemaOptions
* @param {Schema} parentSchema
* @inherits SchemaType
* @api public
*/
function SchemaObjectId(key, options, _schemaOptions, parentSchema) {
const isKeyHexStr = typeof key === 'string' && key.length === 24 && /^[a-f0-9]+$/i.test(key);
const suppressWarning = options?.suppressWarning;
if ((isKeyHexStr || typeof key === 'undefined') && !suppressWarning) {
utils.warn('mongoose: To create a new ObjectId please try ' +
'`Mongoose.Types.ObjectId` instead of using ' +
'`Mongoose.Schema.Types.ObjectId`. Set the `suppressWarning` option if ' +
'you\'re trying to create a hex char path in your schema.');
}
SchemaType.call(this, key, options, 'ObjectId', parentSchema);
}
/**
* This schema type's name, to defend against minifiers that mangle
* function names.
*
* @api public
*/
SchemaObjectId.schemaName = 'ObjectId';
SchemaObjectId.defaultOptions = {};
/*!View on GitHub (pinned to 49cdab0136)
When it happens
Trigger: Thrown at lib/schema/objectId.js:33 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21).
Data as JSON: /api/errors/da8db23bffe2a4f3.
Report an issue: GitHub.