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 ...
Get Learning Single-page Web Application 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.