Last active
February 12, 2017 20:18
-
-
Save shalkam/aff0b3747c999d1a07668568eba5cd08 to your computer and use it in GitHub Desktop.
setting maximum limit for an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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