Mongoose defaults

For completed, we're not going to require it because the completed value is most likely going to default to false. What we can do instead is set the default property, giving this completed field a default value.

  completed: {
    type: Boolean,
    default: false
  },

Now completed, as we talked about earlier in the section, should default to false. There's no reason to create a Todo if it's already done. We can do the same thing for completedAt. If a Todo starts off not completed, then completedAt is not going to exist. It is only going to exist when the Todo has been completed; it's going to be that timestamp. What I'm going to do is set default equal to null:

  completed: {
    type: Boolean,
    default: false }, completedAt: { type: Number, ...

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.