Mongoose is an object data modeling library (ODM) that allows you to define schemas for your data collections. You can find out more about Mongoose on the project website: http://mongoosejs.com/.
To connect to a MongoDB instance using the mongoose
variable, we first need to install npm and save Mongoose. The save
flag automatically adds the module to your package.json
with the latest version, thus, it is always recommended to install your modules with the save flag. For modules that you only need locally (for example, Mocha), you can use the savedev
flag.
For this project, we create a new file db.js
under /src/lib/db.js
, which requires Mongoose. The local connection to the mongodb
database is made in mongoose.connect
as follows:
var mongoose = require('mongoose'); module.exports = function(app) { mongoose.connect('mongodb://localhost/movies', { mongoose: { safe: true } }, function(err) { if (err) { return console.log('Mongoose - connection error:', err...