September 2017
Intermediate to advanced
450 pages
11h 24m
English
Let's follow these steps to add a few different model validations and a new virtual html property to our blog post schema:
var mongoose = require('mongoose');var Schema = mongoose.Schema;function markdownValidator (value) { var regex = new RegExp(/^#*\s/); return !regex.test(value);}var postSchema = new Schema({ title: { type: String, index: 'text', required: true, minlength: 5, maxlength: 64 }, content: { type: String, required: true, validate: [ markdownValidator, 'cannot ...
Read now
Unlock full access