You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling model.validate() on a document field with an array of strings throws an error.
Error: Validation failed: docs.0: Cannot read property 'caster' of undefined
at ValidationError.inspect (node_modules/mongoose/lib/error/validation.js:48:26)
at internal/per_context/primordials.js:23:32
at formatValue (internal/util/inspect.js:774:19)
at inspect (internal/util/inspect.js:336:10)
at formatWithOptionsInternal (internal/util/inspect.js:2006:40)
at formatWithOptions (internal/util/inspect.js:1888:10)
at console.value (internal/console/constructor.js:320:14)
at console.warn (internal/console/constructor.js:353:61)
at validate (bugtest.js:15:13)
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
errors: {
'docs.0': TypeError: Cannot read property 'caster' of undefined
at Proxy._cast (node_modules/mongoose/lib/types/array/methods/index.js:245:36)
at Object.set (node_modules/mongoose/lib/types/array/index.js:72:50)
at node_modules/mongoose/lib/model.js:4261:42
at node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
at new Promise (<anonymous>)
at promiseOrCallback (node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (node_modules/mongoose/lib/index.js:1151:10)
at Function.validate (node_modules/mongoose/lib/model.js:4208:23)
at validate (bugtest.js:13:28)
at Object.<anonymous> (bugtest.js:19:1)
},
_message: 'Validation failed'
}
If the current behavior is a bug, please provide the steps to reproduce.
const { Schema, model } = require('mongoose');
const testSchema = new Schema({
docs: [String],
});
const Test = model('Test', testSchema);
const test = { docs: [ '6132655f2cdb9d94eaebc09b' ] };
async function validate() {
try {
const res = await Test.validate(test);
} catch (e) {
console.error(e);
}
}
validate();
What is the expected behavior?
Validate should succeed. It functions without error in v5.13.8.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 14.15.1
Mongoose: 6.0.4
MongoDB: 4.4.8
The text was updated successfully, but these errors were encountered:
vkarpov15
added
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
labels
Sep 5, 2021
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Calling model.validate() on a document field with an array of strings throws an error.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
Validate should succeed. It functions without error in v5.13.8.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 14.15.1
Mongoose: 6.0.4
MongoDB: 4.4.8
The text was updated successfully, but these errors were encountered: