Now let's create the application's template files. Since we are using the mongoose middleware used in chapter 1, Building a Twitter-Like Application Using the MVC Design Pattern in Node.js, we will keep the same type of configuration:
Create a file called
comments.js
inside the models folder atserver/models
and add the following code:// load the things we need var mongoose = require('mongoose'); var Schema = mongoose.Schema; var commentSchema = mongoose.Schema({ created: { type: Date, default: Date.now }, title: { type: String, default: '', trim: true, required: 'Title cannot be blank' }, content: { type: String, default: '', trim: true }, user: { type: Schema.ObjectId, ref: 'User' } }); module.exports = mongoose.model('Comments', commentSchema);
Create a file called
user.js...