Created
November 15, 2015 02:51
-
-
Save evantahler/0c59aa8680259aee3e01 to your computer and use it in GitHub Desktop.
ActionHero + Mongo
This file contains hidden or 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
exports.default = { | |
mongo: function(api){ | |
return { | |
enable: true, | |
host: '1.2.3.4' | |
port: 27017 | |
db: 'myDatabase' | |
} | |
} | |
} |
This file contains hidden or 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
var mongoPackage = require('mongodb'); | |
var mongo = function (api, next) { | |
api.mongo = {}; | |
api.mongo.client = {}; | |
api.mongo.enable = api.config.mongo.enable; | |
api.mongo.client = mongoPackage.MongoClient; | |
api.log("configuring MongoDB "+api.config.mongo.enable, "notice"); | |
if (api.config.mongo.enable == true) { | |
var url = 'mongodb://'+api.config.mongo.host+':'+api.config.mongo.port+'/'+api.config.mongo.db; | |
api.mongo.client.connect(url, function(err, db) { | |
if(err) { | |
api.log(err+"error in mongoDB connection", "notice"); | |
next(); | |
} else { | |
api.log("mongoDB connection ok ", "notice"); | |
api.mongo.db = db; | |
next(); | |
} | |
}); | |
} | |
} | |
///////////////////////////////////////////////////////////////////// | |
// exports | |
exports.mongo = mongo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
with following error -
/Users/nankisinghchadha/nodejslearningbysumit/actionmongodb/actions/testmongo.js:15
api.mongo.c1.insert(user);
^
TypeError: Cannot read property 'c1' of undefined
at Object.run (/Users/nankisinghchadha/nodejslearningbysumit/actionmongodb/actions/testmongo.js:15:26)
at preProcessAction (/Users/nankisinghchadha/nodejslearningbysumit/actionmongodb/node_modules/actionhero/initializers/actionProcessor.js:278:31)
at /Users/nankisinghchadha/nodejslearningbysumit/actionmongodb/node_modules/async/dist/async.js:3694:9
at /Users/nankisinghchadha/nodejslearningbysumit/actionmongodb/node_modules/async/dist/async.js:359:16
at replenish (/Users/nankisinghchadha/nodejslearningbysumit/actionmongodb/node_modules/async/dist/async.js:876:25)
at /Users/nankisinghchadha/nodejslearningbysumit/actionmongodb/node_modules/async/dist/async.js:885:9
at eachOfLimit (/Users/nankisinghchadha/nodejslearningbysumit/actionmongodb/node_modules/async/dist/async.js:912:22)
at /Users/nankisinghchadha/nodejslearningbysumit/actionmongodb/node_modules/async/dist/async.js:917:16
at _parallel (/Users/nankisinghchadha/nodejslearningbysumit/actionmongodb/node_modules/async/dist/async.js:3685:5)
at Object.series (/Users/nankisinghchadha/nodejslearningbysumit/actionmongodb/node_modules/async/dist/async.js:4525:3)