Creating a brand-new Todo

I'm going to make a variable called newTodo, although you could call it anything you like; the name here is not important. What is important though is that you run the Todo function. This is what comes back from mongoose.model as a constructor function. We want to add the new keyword in front of it because we're creating a new instance of Todo.

Now, the Todo constructor function does take an argument. It's going to be an object where we can specify some of these properties. Maybe we know that we want text to equal something like Cook dinner. Right in the function, we can specify that. text equals a string, Cook dinner:

var newTodo = new Todo({
  text: 'Cook dinner'
});

We haven't required any of our attributes, so ...

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.