Error()
Error.CastError
Error.DivergentArrayError
Error.DocumentNotFoundError
Error.MissingSchemaError
Error.MongooseBulkSaveIncompleteError
Error.MongooseServerSelectionError
Error.OverwriteModelError
Error.ParallelSaveError
Error.StrictModeError
Error.StrictPopulateError
Error.ValidationError
Error.ValidatorError
Error.VersionError
Error.messages
Error.prototype.name
Error()
msg
«String» Error messageMongooseError constructor. MongooseError is the base class for all Mongoose-specific errors.
constModel = mongoose.model('Test', new mongoose.Schema({ answer: Number })); const doc = newModel({ answer: 'not a number' }); const err = doc.validateSync(); err instanceof mongoose.Error.ValidationError; // true
Error.CastError
An instance of this error class will be thrown when mongoose failed to cast a value.
Error.DivergentArrayError
An instance of this error will be thrown if you used an array projection and then modified the array in an unsafe way.
Error.DocumentNotFoundError
An instance of this error class will be thrown when save()
fails because the underlying document was not found. The constructor takes one parameter, the conditions that mongoose passed to updateOne()
when trying to update the document.
Error.MissingSchemaError
Thrown when you try to access a model that has not been registered yet
Error.MongooseBulkSaveIncompleteError
Thrown when some documents failed to save when calling bulkSave()
Error.MongooseServerSelectionError
Thrown when the MongoDB Node driver can't connect to a valid server to send an operation to.
Error.OverwriteModelError
Thrown when a model with the given name was already registered on the connection. See the FAQ about OverwriteModelError
.
Error.ParallelSaveError
An instance of this error class will be thrown when you call save()
multiple times on the same document in parallel. See the FAQ for more information.
Error.StrictModeError
Thrown when your try to pass values to model constructor that were not specified in schema or change immutable properties when strict
mode is "throw"
Error.StrictPopulateError
An instance of this error class will be returned when mongoose failed to populate with a path that is not existing.
Error.ValidationError
An instance of this error class will be thrown when validation failed. The errors
property contains an object whose keys are the paths that failed and whose values are instances of CastError or ValidationError.
Error.ValidatorError
A ValidationError
has a hash of errors
that contain individual ValidatorError
instances.
const schema = Schema({ name: { type: String, required: true } }); constModel = mongoose.model('Test', schema); const doc = newModel({}); // Top-level error is a ValidationError, **not** a ValidatorErrorconst err = doc.validateSync(); err instanceof mongoose.Error.ValidationError; // true// A ValidationError `err` has 0 or more ValidatorErrors keyed by the// path in the `err.errors` property. err.errors['name'] instanceof mongoose.Error.ValidatorError; err.errors['name'].kind; // 'required' err.errors['name'].path; // 'name' err.errors['name'].value; // undefined
Instances of ValidatorError
have the following properties:
kind
: The validator's type
, like 'required'
or 'regexp'
path
: The path that failed validationvalue
: The value that failed validationError.VersionError
An instance of this error class will be thrown when you call save()
after the document in the database was changed in a potentially unsafe way. See the versionKey
option for more information.
Error.messages
The default built-in validator error messages.
Error.prototype.name
The name of the error. The name uniquely identifies this Mongoose error. The possible values are:
MongooseError
: general Mongoose errorCastError
: Mongoose could not convert a value to the type defined in the schema path. May be in a ValidationError
class' errors
property.DivergentArrayError
: You attempted to save()
an array that was modified after you loaded it with a $elemMatch
or similar projectionMissingSchemaError
: You tried to access a model with mongoose.model()
that was not definedDocumentNotFoundError
: The document you tried to save()
was not foundValidatorError
: error from an individual schema path's validatorValidationError
: error returned from validate()
or validateSync()
. Contains zero or more ValidatorError
instances in .errors
property.MissingSchemaError
: You called mongoose.Document()
without a schemaObjectExpectedError
: Thrown when you set a nested path to a non-object value with strict mode set.ObjectParameterError
: Thrown when you pass a non-object value to a function which expects an object as a paramterOverwriteModelError
: Thrown when you call mongoose.model()
to re-define a model that was already defined.ParallelSaveError
: Thrown when you call save()
on a document when the same document instance is already saving.StrictModeError
: Thrown when you set a path that isn't the schema and strict mode is set to throw
.VersionError
: Thrown when the document is out of sync