O'Reilly logo

Web Development with MongoDB and NodeJS - Second Edition by Jason Krol, Bruno Joseph D'mello, Mithun Satheesh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining the schemas and models

For the purposes of the application we are building, we're only going to have two different unique schemas and associated models: an Image model and a Comment model. If we were to take this application to production and really build it out with all of the necessary features, we could expect to have many more models as well.

First, create a new directory labeled models in your project and we will store the Node.js modules for each of our models here. Create three files named image.js, comment.js, and index.js in this directory. Let's take a look at the Image model first. Copy the following block of code into the models/image.j s file:

var mongoose = require('mongoose'), Schema = mongoose.Schema, path = require('path'); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required