Customizing the Todo text property

To kick things off, let's customize how Mongoose treats our text property. Currently, we tell Mongoose that we want it to be a string, but we don't have any validators. One of the first things we can do for the text property is set required equal to true.

var Todo = mongoose.model('Todo', {  text: {    type: String,    required: true  },

When you set required equal to true, the value must exist, so if I were to try to save this Todo it would fail. And we can prove this. We can save the file, head over to the Terminal, shut things down, and restart it:

We get an unreadable error message. We'll dive into this in a ...

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.