Book Image

Learning Single-page Web Application Development

Book Image

Learning Single-page Web Application Development

Overview of this book

Table of Contents (15 chapters)
Learning Single-page Web Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Model with the Mongoose schema


Now, let's create our model, using the Mongoose schema to map our speakers on MongoDB.

// Import the Mongoose module.
var mongoose     = require('mongoose');
var Schema       = mongoose.Schema;

// Set the data types, properties and default values to our Schema.
var SpeakerSchema   = new Schema({
    name:           { type: String, default: '' },
    company:        { type: String, default: '' },
    title:          { type: String, default: '' },
    description:    { type: String, default: '' },
    picture:        { type: String, default: '' },
    schedule:       { type: String, default: '' },
    createdOn:      { type: Date,   default: Date.now}
});
module.exports = mongoose.model('Speaker', SpeakerSchema);

Note that on the first line, we added the Mongoose module using the require() function.

Our schema is pretty simple; on the left-hand side, we have the property name and on the right-hand side, the data type. We also we set the default value to nothing...