Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
mongoose = require 'mongoose'
db = mongoose.createConnection(, 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