Skip to content

Instantly share code, notes, and snippets.

@shalkam
Last active February 12, 2017 20:18
Show Gist options
  • Save shalkam/aff0b3747c999d1a07668568eba5cd08 to your computer and use it in GitHub Desktop.
Save shalkam/aff0b3747c999d1a07668568eba5cd08 to your computer and use it in GitHub Desktop.
setting maximum limit for an array
var peopleSchema = new Schema({
name: {
type: String,
required: true,
default: true
},
friends: {
type: [{
type: Schema.Types.ObjectId,
ref: 'peopleModel'
}],
validate: [arrayLimit, '{PATH} exceeds the limit of 10']
}
});
function arrayLimit(val) {
return val.length <= 10;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment