Reputation: 17999
I'm trying to have a Role that contains an array of access.
access: [{
type: 'string',
match: /^[a-zA-Z]+$/,
required: true,
notEmpty: true,
check: {
minLength: 2
}
}]
I get:
node_modules\mongoose\lib\schema\array.js:58
this.caster = new caster(null, castOptions);
^
TypeError: string is not a function
If I replace type: 'string'
by type: String
it works. Why?
If I try to add an index on the array it doesn't works. (index: true
)
Do I have to do a collection.index({'access': 1})
?
Upvotes: 3
Views: 6837
Reputation: 145994
type: String,
is what you want on line 2. Mongoose expects the type to point to a function that can be used to coerce values to the correct type.
Upvotes: 4