meanjs app deploy mongodb connection fails but works local

381 views Asked by At

meanjs app, database connection fail (mongoHQ), string hard coded:

db: 'mongodb://user:[email protected]/db_name'

1) package.json: https://gist.github.com/anonymous/c864fbc2572bd10f7e90 
2) log error: https://gist.github.com/anonymous/09726b7458560fe8e5f3 
3) jitsu v0.14.0, node v0.10.33 and npm v2.1.8 
4) platform : linux

db string above is used for development and production environment for testing purpose. Issue is that I can connect and add entries to the database in a local environment (dev env) but once I deploy or push to either herokuapp or nodejitsu I get the following error:

nodejitsu log:

    out Wed, 19 Nov 2014 23:39:34 GMT 
    out Wed, 19 Nov 2014 23:39:34 GMT Application loaded using the "production" environment configuration
    out Wed, 19 Nov 2014 23:39:34 GMT 
    err Wed, 19 Nov 2014 23:39:36 GMT 
    err Wed, 19 Nov 2014 23:39:36 GMT events.js:72
    err Wed, 19 Nov 2014 23:39:36 GMT ^
    err Wed, 19 Nov 2014 23:39:36 GMT throw er; // Unhandled 'error' event
    err Wed, 19 Nov 2014 23:39:36 GMT Error: failed to connect to [localhost:27017]
    at null. (/opt/run/snapshot/package/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:549:74)
    at emit (events.js:106:17)
    at null. (/opt/run/snapshot/package/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:150:15)
    at emit (events.js:98:17)
    at Socket. (/opt/run/snapshot/package/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:533:10)
    at Socket.emit (events.js:95:17)
    at net.js:440:14
    at process._tickCallback (node.js:419:13)

heroku log:

2014-11-19T23:27:22.425635+00:00 app[web.1]: MEAN.JS application started on port 15050
2014-11-19T23:27:22.430865+00:00 app[web.1]: events.js:72
2014-11-19T23:27:22.434306+00:00 app[web.1]:               ^
2014-11-19T23:27:22.430483+00:00 app[web.1]: 
2014-11-19T23:27:22.436997+00:00 app[web.1]:     at emit (events.js:106:17)
2014-11-19T23:27:22.437004+00:00 app[web.1]:     at Socket.emit (events.js:95:17)
2014-11-19T23:27:22.437006+00:00 app[web.1]:     at net.js:440:14
2014-11-19T23:27:22.431432+00:00 app[web.1]:         throw er; // Unhandled 'error' event
2014-11-19T23:27:22.436991+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
2014-11-19T23:27:22.436996+00:00 app[web.1]:     at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:549:74)
2014-11-19T23:27:22.436999+00:00 app[web.1]:     at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:150:15)
2014-11-19T23:27:22.437001+00:00 app[web.1]:     at emit (events.js:98:17)
2014-11-19T23:27:22.437003+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:533:10)
2014-11-19T23:27:22.437008+00:00 app[web.1]:     at process._tickCallback (node.js:419:13)
2014-11-19T23:27:22.452476+00:00 app[web.1]: error: Forever detected script exited with code: 8
1

There are 1 answers

0
lightbots On

I found a connection code in one of my models needed for an auto-increment plugin.

var connection = mongoose.createConnection('mongodb://localhost/n-express-dev');

replaced with the following to get it to deploy without errors.

var connection = mongoose.createConnection(process.env.MONGOHQ_URI || process.env.MONGOLAB_URI || 'mongodb://localhost/n-express-dev');