Reputation: 583
Am still new to node and currently using node version 10.5.0 and mongoose version 5.1.7. I have carefully checked existing questions concerning mlab but none is addressing my issue. Am trying to connect to mLab here is my code:
const mongoose = require('mongoose');
const dbUri = 'mongodb://username:[email protected]:21371/kucubookstore';
// connecting to mlab mongodb
mongoose.connect(dbUri, function(error) {
console.log('Connection Successful', error);
});
however am getting the following error and I don't understand it. Please help:
E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue>node test/connection.js
Connection Successful Error: Missing delimiting slash between hosts and options
at parseConnectionString (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\url_parser.js:164:11)
at parseHandler (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\url_parser.js:129:14)
at module.exports (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\url_parser.js:25:12)
at connect (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\mongo_client.js:880:3)
at connectOp (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\mongo_client.js:270:3)
at executeOperation (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\utils.js:420:24)
at MongoClient.connect (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\mongo_client.js:261:10)
at Promise (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongoose\lib\connection.js:436:12)
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongoose\lib\connection.js:433:19)
at Mongoose.connect (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongoose\lib\index.js:212:15)
at Object.<anonymous> (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\test\connection.js:5:10)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
(node:9016) UnhandledPromiseRejectionWarning: Error: Missing delimiting slash between hosts and options
at parseConnectionString (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\url_parser.js:164:11)
at parseHandler (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\url_parser.js:129:14)
at module.exports (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\url_parser.js:25:12)
at connect (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\mongo_client.js:880:3)
at connectOp (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\mongo_client.js:270:3)
at executeOperation (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\utils.js:420:24)
at MongoClient.connect (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\mongo_client.js:261:10)
at Promise (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongoose\lib\connection.js:436:12)
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongoose\lib\connection.js:433:19)
at Mongoose.connect (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongoose\lib\index.js:212:15)
at Object.<anonymous> (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\test\connection.js:5:10)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
(node:9016) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:9016) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Upvotes: 2
Views: 300
Reputation: 3452
This error happens when your password contains special characters (like @
) that has a special meaning in the URL. Try changing the password to something simple like only Alphanumeric Characters or to escape those characters (https://www.w3schools.com/tags/ref_urlencode.asp).
For example, if you have your password as set as one@two
, then change that to one%40two
.
Try connecting using some VPN if you think your internet provider lacks connectivity with that server.
Upvotes: 1