Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
In this video, learn how to create a schema for MongoDB using Mongoose. You'll learn how to create a document schema with keys and additional properties to control the type of data Mongoose will store in MongoDB.
Resources
Mongoose Schemas Mongoose Methods
User model code for user.js
:
var mongoose = require('mongoose');
var UserSchema = new mongoose.Schema({
email: {
type: String,
required: true,
trim: true,
unique: true,
},
name: {
type: String,
required: true,
trim: true,
},
favoriteBook: {
type: String,
required: true,
trim: true
},
password: {
type: String,
required: true
}
});
var User = mongoose.model('User', UserSchema);
module.exports = User;
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up