Hi,
Thx for the response, finaly found a solution:
// i define roles as an array
var User = new Schema({
...
roles: [String]
...
});
// and validate the values match the content of the enum:
User.path('roles').validate(function(roles) {
var refs = ['creator', 'admin', 'contact'];
roles.forEach(function(role){
var valid = false;
refs.forEach(function(ref){
if(ref == role) {
valid = true;
return;
}
});
if(!valid) return false;
});
return roles.length > 0;
}, 'roles not valid');
On Jul 6, 3:41 pm, dale tan <
wtd...@gmail.com> wrote:
> defining the "roles" as type String with an enum seems to be a good way to
> cast that value. You can also add a "default" property as one of the enum
> values if you'd like. You can see this in action here:
http://nodetuts.com/tutorials/21-nodejs-mongodb-and-mongoose-11.html#...