Configuring Node.js Connection String for Mongo Labs Database on Heroku

后端 未结 1 1537
余生分开走
余生分开走 2021-01-16 09:05

My web app (built on Node.js and Express) works fine locally, but when I deploy it to Heroku, I\'m unable to connect to my Mongo Labs database. I\'ve changed the connection

1条回答
  •  执念已碎
    2021-01-16 09:55

    I answered this in the comments on my tutorial, but I'll answer it here too: I think it's likely that you need to use the environment variable referenced in the Heroku ducomentation you linked: process.env.MONGOLAB_URI ... my guess is that Heroku doesn't want you putting your username/password directly into the code (and with good reason, since that's not particularly secure). Give it a shot with:

    var db = mongo.db(process.env.MONGOLAB_URI, {native_parser:true});
    

    and see how that works out.

    0 讨论(0)
提交回复
热议问题