Skip to content

Instantly share code, notes, and snippets.

@cdolivares
Created August 14, 2012 19:53
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 cdolivares/3352248 to your computer and use it in GitHub Desktop.
Save cdolivares/3352248 to your computer and use it in GitHub Desktop.
#connectDb.coffee
module.exports = (mongoString) ->
mongoose = require 'mongoose'
db = mongoose.createConnection mongoString
return db
#dbConfig.coffee
module.exports = (mongoInstance) ->
models = {}
mongoInstance.model "youModel", youSchema
models.youModel = mongoInstance "youModel"
#CONFIG DB HERE
return models
#app.coffee
db = require('connectDb)("mongoString") #require returns a function. the second parenthesis executes function
dbWithModels = require('dbConfig')(db)
dbWithModels.youModels.find etc....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment