ga-wdi-boston / team-project

Other
2 stars 39 forks source link

Deployment to Heroku fails to connect to MongoServer #172

Closed DanielJRaine closed 8 years ago

DanielJRaine commented 8 years ago

I tried setting up MongoLab, but I don't know if I'm missing something because it keeps failing to connect to Mongo on the backend.

I tried going through all of the closed issues that have similar error messages, but no solution I found there seems to work.

Here are my Heroku Logs:

2016-10-17T20:23:52.961619+00:00 heroku[slug-compiler]: Slug compilation finished
2016-10-17T20:23:53.226618+00:00 heroku[web.1]: State changed from crashed to starting
2016-10-17T20:23:55.674070+00:00 heroku[web.1]: Starting process with command `npm start`
2016-10-17T20:23:59.020247+00:00 app[web.1]: 
2016-10-17T20:23:59.020259+00:00 app[web.1]: > express-api-template@0.1.0 start /app
2016-10-17T20:23:59.020260+00:00 app[web.1]: > ./bin/express server
2016-10-17T20:23:59.020261+00:00 app[web.1]: 
2016-10-17T20:23:59.686501+00:00 app[web.1]: 
2016-10-17T20:23:59.686511+00:00 app[web.1]: /app/node_modules/mongodb/lib/server.js:261
2016-10-17T20:23:59.686514+00:00 app[web.1]:         process.nextTick(function() { throw err; })
2016-10-17T20:23:59.686515+00:00 app[web.1]:                                       ^
2016-10-17T20:23:59.687448+00:00 app[web.1]: MongoError: failed to connect to server [undefined:27017] on first connect
2016-10-17T20:23:59.687451+00:00 app[web.1]:     at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:313:35)
2016-10-17T20:23:59.687452+00:00 app[web.1]:     at emitOne (events.js:96:13)
2016-10-17T20:23:59.687452+00:00 app[web.1]:     at Pool.emit (events.js:188:7)
2016-10-17T20:23:59.687453+00:00 app[web.1]:     at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:260:12)
2016-10-17T20:23:59.687454+00:00 app[web.1]:     at Connection.g (events.js:291:16)
2016-10-17T20:23:59.687454+00:00 app[web.1]:     at emitTwo (events.js:106:13)
2016-10-17T20:23:59.687455+00:00 app[web.1]:     at Connection.emit (events.js:191:7)
2016-10-17T20:23:59.687456+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:162:49)
2016-10-17T20:23:59.687456+00:00 app[web.1]:     at Socket.g (events.js:291:16)
2016-10-17T20:23:59.687457+00:00 app[web.1]:     at emitOne (events.js:96:13)
2016-10-17T20:23:59.687457+00:00 app[web.1]:     at Socket.emit (events.js:188:7)
2016-10-17T20:23:59.687458+00:00 app[web.1]:     at connectErrorNT (net.js:1020:8)
2016-10-17T20:23:59.687459+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:74:11)
2016-10-17T20:23:59.687459+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:98:9)
2016-10-17T20:23:59.696530+00:00 app[web.1]: 
2016-10-17T20:23:59.703794+00:00 app[web.1]: npm ERR! Linux 3.13.0-93-generic
2016-10-17T20:23:59.704058+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-10-17T20:23:59.704383+00:00 app[web.1]: npm ERR! node v6.8.1
2016-10-17T20:23:59.704563+00:00 app[web.1]: npm ERR! npm  v3.10.8
2016-10-17T20:23:59.704745+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-10-17T20:23:59.704889+00:00 app[web.1]: npm ERR! express-api-template@0.1.0 start: `./bin/express server`
2016-10-17T20:23:59.705012+00:00 app[web.1]: npm ERR! Exit status 1
2016-10-17T20:23:59.705146+00:00 app[web.1]: npm ERR! 
2016-10-17T20:23:59.705276+00:00 app[web.1]: npm ERR! Failed at the express-api-template@0.1.0 start script './bin/express server'.
2016-10-17T20:23:59.705397+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2016-10-17T20:23:59.705518+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the express-api-template package,
2016-10-17T20:23:59.705638+00:00 app[web.1]: npm ERR! not with npm itself.
2016-10-17T20:23:59.705769+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-10-17T20:23:59.706013+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-10-17T20:23:59.705891+00:00 app[web.1]: npm ERR!     ./bin/express server
2016-10-17T20:23:59.706134+00:00 app[web.1]: npm ERR!     npm bugs express-api-template
2016-10-17T20:23:59.706254+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-10-17T20:23:59.706375+00:00 app[web.1]: npm ERR!     npm owner ls express-api-template
2016-10-17T20:23:59.706493+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-10-17T20:23:59.709751+00:00 app[web.1]: 
2016-10-17T20:23:59.709938+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-10-17T20:23:59.710047+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-10-17T20:23:59.788002+00:00 heroku[web.1]: State changed from starting to crashed
2016-10-17T20:23:59.783377+00:00 heroku[web.1]: Process exited with status 1
2016-10-17T20:24:07.030547+00:00 heroku[web.1]: State changed from crashed to starting
2016-10-17T20:24:08.519227+00:00 heroku[web.1]: Starting process with command `npm start`
2016-10-17T20:24:10.924205+00:00 app[web.1]: 
2016-10-17T20:24:10.924260+00:00 app[web.1]: > express-api-template@0.1.0 start /app
2016-10-17T20:24:10.924261+00:00 app[web.1]: > ./bin/express server
2016-10-17T20:24:10.924262+00:00 app[web.1]: 
2016-10-17T20:24:11.659312+00:00 app[web.1]: 
2016-10-17T20:24:11.660140+00:00 app[web.1]:     at emitTwo (events.js:106:13)
2016-10-17T20:24:11.660143+00:00 app[web.1]:     at connectErrorNT (net.js:1020:8)
2016-10-17T20:24:11.660144+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:98:9)
2016-10-17T20:24:11.676386+00:00 app[web.1]: npm ERR! Linux 3.13.0-95-generic
2016-10-17T20:24:11.677495+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2016-10-17T20:24:11.659323+00:00 app[web.1]: /app/node_modules/mongodb/lib/server.js:261
2016-10-17T20:24:11.676828+00:00 app[web.1]: npm ERR! node v6.8.1
2016-10-17T20:24:11.677169+00:00 app[web.1]: npm ERR! express-api-template@0.1.0 start: `./bin/express server`
2016-10-17T20:24:11.659325+00:00 app[web.1]:                                       ^
2016-10-17T20:24:11.660138+00:00 app[web.1]:     at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:313:35)
2016-10-17T20:24:11.660140+00:00 app[web.1]:     at Connection.g (events.js:291:16)
2016-10-17T20:24:11.660141+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:162:49)
2016-10-17T20:24:11.669246+00:00 app[web.1]: 
2016-10-17T20:24:11.676566+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-10-17T20:24:11.659324+00:00 app[web.1]:         process.nextTick(function() { throw err; })
2016-10-17T20:24:11.660136+00:00 app[web.1]: MongoError: failed to connect to server [undefined:27017] on first connect
2016-10-17T20:24:11.660139+00:00 app[web.1]:     at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:260:12)
2016-10-17T20:24:11.660141+00:00 app[web.1]:     at Connection.emit (events.js:191:7)
2016-10-17T20:24:11.677572+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the express-api-template package,
2016-10-17T20:24:11.677649+00:00 app[web.1]: npm ERR! not with npm itself.
2016-10-17T20:24:11.660138+00:00 app[web.1]:     at emitOne (events.js:96:13)
2016-10-17T20:24:11.660141+00:00 app[web.1]:     at Socket.g (events.js:291:16)
2016-10-17T20:24:11.676943+00:00 app[web.1]: npm ERR! npm  v3.10.8
2016-10-17T20:24:11.677735+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-10-17T20:24:11.677811+00:00 app[web.1]: npm ERR!     ./bin/express server
2016-10-17T20:24:11.660139+00:00 app[web.1]:     at Pool.emit (events.js:188:7)
2016-10-17T20:24:11.660142+00:00 app[web.1]:     at emitOne (events.js:96:13)
2016-10-17T20:24:11.677068+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-10-17T20:24:11.677419+00:00 app[web.1]: npm ERR! Failed at the express-api-template@0.1.0 start script './bin/express server'.
2016-10-17T20:24:11.681492+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-10-17T20:24:11.660142+00:00 app[web.1]:     at Socket.emit (events.js:188:7)
2016-10-17T20:24:11.660143+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:74:11)
2016-10-17T20:24:11.677247+00:00 app[web.1]: npm ERR! Exit status 1
2016-10-17T20:24:11.677335+00:00 app[web.1]: npm ERR! 
2016-10-17T20:24:11.678043+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-10-17T20:24:11.678192+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-10-17T20:24:11.677890+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-10-17T20:24:11.678115+00:00 app[web.1]: npm ERR!     npm owner ls express-api-template
2016-10-17T20:24:11.681578+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-10-17T20:24:11.677964+00:00 app[web.1]: npm ERR!     npm bugs express-api-template
2016-10-17T20:24:11.681342+00:00 app[web.1]: 
2016-10-17T20:24:11.749427+00:00 heroku[web.1]: Process exited with status 1
2016-10-17T20:24:11.740129+00:00 heroku[web.1]: State changed from starting to crashed
berziiii commented 8 years ago

If you set it up correctly, you should have a config variable in Heroku that has something to do with mongo. If so, what if that variable key?

If you don't know what I'm referring to, then you should revisit the deployment steps in issue #222

jrhorn424 commented 8 years ago

Yes, you'll need to make sure whatever heroku sets for your environment variable (the name of the variable) matches whatever the mongo config variable is in your code.

DanielJRaine commented 8 years ago

I have both my MONGODB_URI: mongodb://danieljley:SYBRgr33n@ds023425.mlab.com:23425/heroku_f7bkwspp

as well as a PROD_MONGODB: mongodb://danieljley:SYBRgr33n@ds023425.mlab.com:23425/heroku_f7bkwspp

config variables set up (depending on which guide you follow, it has you generate one or both of these config variables).

This repo does not have an issue #222. Which issue are you referring to?

DanielJRaine commented 8 years ago

The config variable in the express-api-template that was provided uses MONGOLAB_URI, but that does not match with what Heroku gave me when following its guides for mLab, so I commented out the MONGOLAB_URI and instead used the above MONGODB_URI whenever process.env is invoked to find my db URI.

Should I be using the config variable given to us in the template or the one that is generated by Heroku/mLab? (it's just a name, so it shouldn't matter as long as my Heroku config variables match with the code itself, but this was not covered in any deployment guide given to us or in the express-api-template, so I don't want to make too many assumptions)

DanielJRaine commented 8 years ago

I have followed the mLab documentation as far as using a Node Driver, but I am getting really confused at this part, because I don't know if the Node Driver (used to connect to my MongoDB instance) is something I need to add as a .js file into my code, or if it's something I just need to execute in a Node shell in Heroku, or something else. The Heroku Documentation only really goes over the Ruby example for setting up a driver to hook up to your Mongo database and it only provides not-very-useful references for using any other language (i.e., Node).

DanielJRaine commented 8 years ago

I keep getting these errors when I try to use the shell scripts provided at mLab's website (https://mlab.com/databases/bucket-list-api#users) :

To connect using the mongo shell: mongo ds025742.mlab.com:25742/bucket-list-api -u <dbuser> -p <dbpassword> To connect using a driver via the standard MongoDB URI (what's this?): mongodb://<dbuser>:<dbpassword>@ds025742.mlab.com:25742/bucket-list-api

~ $ mongodb://danieljley:SYBRgr33n@ds025742.mlab.com:25742/bucket-list-api
bash: mongodb://danieljley:SYBRgr33n@ds025742.mlab.com:25742/bucket-list-api: No such file or directory
~ $ mongo ds025742.mlab.com:25742/bucket-list-api -u <dbuser> -p <dbpassword>
bash: syntax error near unexpected token `newline'
~ $ mongo
MongoDB shell version: 2.6.10
connecting to: test
> 
bye
~ $  mongo ds025742.mlab.com:25742/bucket-list-api -u <dbuser> -p <dbpassword>
bash: syntax error near unexpected token `newline'
~ $ mongo ds025742.mlab.com:25742/bucket-list-api -u danieljley -p SYBRgr33n
MongoDB shell version: 2.6.10
connecting to: ds025742.mlab.com:25742/bucket-list-api
2016-10-18T09:09:41.524-0400 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1287
exception: login failed
jrhorn424 commented 8 years ago

This is way more than you should have to do. Please stop going further into the hole. You should be able to work with the linked resources. If it isn't possible, we should work on it together so we can record what we can improve in the future.

DanielJRaine commented 8 years ago

May I come find you to work through this?

jrhorn424 commented 8 years ago

That was a really dry way of saying "Let's work on this together: one of us may have goofed and I'm not sure who". So yeah, come by. I'll be in the classroom in a moment.

DanielJRaine commented 8 years ago

I would be more than happy to help write up a guide on this after the project is over if it means saving someone from this level of frustration in the future.

jrhorn424 commented 8 years ago

https://github.com/ga-wdi-boston/capstone-project/issues/222

jrhorn424 commented 8 years ago

I believe we resolved this. @DanielJRaine feel free to add any notes here or at https://github.com/ga-wdi-boston/capstone-project/issues/222. Thanks!