Vadorequest Vadorequest - 1 month ago 10
Node.js Question

array of string in a schema mongoose

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:

this.caster = new caster(null, castOptions);
TypeError: string is not a function

If I replace
type: 'string'
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})


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.