I am following a book's instructions. I have no trouble connecting to the local database or to MongoLab online in terminal, but can't run my app locally using my Heroku database with: NODE_ENV=production nodemon bin/www
This is my check in my code to use the online database depending on how I start the app:
if (process.env.NODE_ENV === 'production') {
dbURI= process.env.MONGOLAB_URI;
}
I manually input: heroku config:set MONGOLAB_URI=[my uri] as well as used the heroku config:get MONGOLAB_URI and keep getting: Error: failed to connect to [undefined:27017]
Does anybody have any ideas why I can't connect?
~ $ node app.js
/app/node_modules/connect-mongo/node_modules/mongodb/lib/server.js:228
process.nextTick(function() { throw err; })
^
Error
at Error.MongoError (/app/node_modules/connect-mongo/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:13:17)
at Server.destroy (/app/node_modules/connect-mongo/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:629:47)
at Server.close (/app/node_modules/connect-mongo/node_modules/mongodb/lib/server.js:344:17)
at Db.close (/app/node_modules/connect-mongo/node_modules/mongodb/lib/db.js:267:19)
at /app/node_modules/connect-mongo/node_modules/mongodb/lib/db.js:196:12
at null.<anonymous> (/app/node_modules/connect-mongo/node_modules/mongodb/lib/server.js:226:9)
at g (events.js:180:16)
at emit (events.js:98:17)
at null.<anonymous> (/app/node_modules/connect-mongo/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:238:68)
at g (events.js:180:16)
at emit (events.js:98:17)
at null.<anonymous> (/app/node_modules/connect-mongo/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:77:12)
at g (events.js:180:16)
at emit (events.js:98:17)
at Socket.<anonymous> (/app/node_modules/connect-mongo/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:118:49)
at Socket.g (events.js:180:16)
~ $
^^ I am seeing the above My connection:
omeMongodbServer: { adapter: 'sails-mongo', url: process.env.MONGOLAB_URI || 'mongodb://localhost/ts', },