I have an application I attempting to connect to an mLab environment using Mongoose. I have the following code configured to attempt to connect to an mLab MongoDB Instance.
mongoose.connect(process.env.MONGODB_URI);
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', () => {});
The variable process.env.MONGODB_URI
is equal to
mongodb://user:password@ds123456.mlab.com:12345/someRandomName
(identifiers psuedonymized for privacy).
Applicable Software Versions
Node: v10.7.0
NPM: 6.2.0
Mongoose: 5.2.6
When I try to run the application I get the following error.
node ./bin/www
(node:2555) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
connection error: Error: Slash in host identifier
at parseConnectionString (/Users/nathanielsuchy/Documents/control-panel/node_modules/mongoose/node_modules/mongodb/lib/url_parser.js:219:15)
at parseHandler (/Users/nathanielsuchy/Documents/control-panel/node_modules/mongoose/node_modules/mongodb/lib/url_parser.js:129:14)
at module.exports (/Users/nathanielsuchy/Documents/control-panel/node_modules/mongoose/node_modules/mongodb/lib/url_parser.js:25:12)
at deprecated (internal/util.js:70:15)
at connect (/Users/nathanielsuchy/Documents/control-panel/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:179:3)
at connectOp (/Users/nathanielsuchy/Documents/control-panel/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:283:3)
at executeOperation (/Users/nathanielsuchy/Documents/control-panel/node_modules/mongoose/node_modules/mongodb/lib/utils.js:420:24)
at MongoClient.connect (/Users/nathanielsuchy/Documents/control-panel/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:168:10)
at Promise (/Users/nathanielsuchy/Documents/control-panel/node_modules/mongoose/lib/connection.js:493:12)
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (/Users/nathanielsuchy/Documents/control-panel/node_modules/mongoose/lib/connection.js:490:19)
at Mongoose.connect (/Users/nathanielsuchy/Documents/control-panel/node_modules/mongoose/lib/index.js:230:15)
at Object.<anonymous> (/Users/nathanielsuchy/Documents/control-panel/app.js:20:10)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
I am lead to two conclusions. One I need to use the new URL parser, second there's an issue I'm not seeing in my database connection string format. How should I proceed to fix the issue?