Our complete code

Now that we have defined our schemas and compiled the models, let's take a look at our /model/db.js file.

var mongoose = require( 'mongoose' ), dbURI = 'mongodb://localhost/MongoosePM'; mongoose.connect(dbURI); // Connection events snipped out for brevity /* ******************************************** USER SCHEMA ******************************************** */ var userSchema = new mongoose.Schema({ name: String, email: {type: String, unique:true}, createdOn: { type: Date, default: Date.now }, modifiedOn: Date, lastLogin: Date }); // Build the User model mongoose.model( 'User', userSchema ); /* ******************************************** PROJECT SCHEMA ******************************************** */ var projectSchema = new mongoose.Schema({ ...

Get Mongoose for 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.