How to define, maintain and use a Mongoose database connection
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
model Minor tweaks Oct 14, 2013
.gitignore First commit Aug 23, 2013
app.js Fleshed out the example Aug 24, 2013
package.json First commit Aug 23, 2013
pages.js Minor update to match blog post Aug 26, 2013
readme.md Minor update to match blog post Aug 26, 2013

readme.md

Mongoose Default Connection

A quick guide to the best practice for creating, maintaining and using a default Mongoose connection.

The connection is managed in /model/db.js. It is opened at application start, and closed on application termination. In this file we also monitor the connected, error and disconnected events.

A sample Mongoose schema is defined and model built in /model/team.js. All of the relevant code is in /model/db.js.

app.js is just a minimal Node.js skeleton, rendering a page defined in pages.js. pages.js brings in Mongoose and the model defined in /model/team.js.

This only requires Mongoose in the application, as noted in package.json. If you download this you can install Mongoose into the application by running npm install

More detailed discussion around using this is available on my blog: http://theholmesoffice.com/mongoose-connection-best-practice/