Created
November 8, 2012 02:56
-
-
Save bencevans/4036327 to your computer and use it in GitHub Desktop.
Mongoose Bootstrap.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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