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, but if you want, you can set a different value.
The next step is to save this file to our project folder. For this, let's create a new directory named server
; then inside this, create another folder called models
and save the file as speaker.js
. At this point, our folder looks like this:
18.188.187.165