Skip to content

Instantly share code, notes, and snippets.

@bencevans
Created November 8, 2012 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bencevans/4036327 to your computer and use it in GitHub Desktop.
Save bencevans/4036327 to your computer and use it in GitHub Desktop.
Mongoose Bootstrap.coffee
mongoose = require 'mongoose'
db = mongoose.createConnection(config.mongo.host, config.mongo.db);
db.on 'error', console.error.bind(console, 'connection error:')
db.once 'open', () ->
console.log 'Connected to DB'
schemaFiles = fs.readdirSync './db/schemas'
for filename in schemaFiles
splitFilename = filename.split '.'
schemaName = splitFilename[0].charAt(0).toUpperCase() + splitFilename[0].slice(1);
global[schemaName] = db.model schemaName, new mongoose.Schema(require('./db/schemas/' + filename))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment