-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
Do you want to request a feature or report a bug?
Report a bug
What is the current behavior?
After defining my schema similar to the following one:
const UserSchema = new mongoose.Schema({
roles: {
type: [String],
index: true,
},
});
mongoose.model('User', UserSchema)If I try to instantiate a new User like this:
const user = new User({ roles: ['super-admin'] });It raises the following exception ValidationError: User validation failed: roles: Cast to Array failed for value "[ 'super-admin' ]" at path "roles"
Instantiating the user with an empty roles array does not raise any exception.
This is happening on [email protected], downgrading to 5.6.8 fixes it.
If the current behavior is a bug, please provide the steps to reproduce.
The schema shown above should be enough to reproduce the issue.
What is the expected behavior?
No ValidationError exception raised when instantiating a model with an array in the schema.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node 10.16.0
mongoose 5.6.9
mongo 4.0.4