Vadorequest Vadorequest - 1 year ago 119
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})

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download