2

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:password@ds121371.mlab.com: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.
Eric O.
  • 474
  • 4
  • 23
  • Are you using your own `username` and `password` instead of the placeholder `username:password`? – Saif Jun 28 '18 at 20:35
  • Also add your `package.json` file. – Saif Jun 28 '18 at 20:41
  • I tried running the same node file in my computer and this seems to work. – Saif Jun 28 '18 at 20:46
  • yes I have the username and password. – Eric O. Jun 28 '18 at 20:56
  • Head over to https://mlab.com/databases/kucubookstore#users and try creating a new user with a new username and password and copy the exact same URL given on https://mlab.com/databases/kucubookstore (Something like, `mongodb://:@ds123456.mlab.com:1234/kucubookstore`) with your own newly created username and password. – Saif Jun 28 '18 at 21:01
  • For example if the new username and password is `admin:mynewpwd123`, replace `:` with `admin:mynewpwd123` in the URL. – Saif Jun 28 '18 at 21:03
  • https://stackoverflow.com/questions/42170685/mongodb-driver-missing-delimiting-slash-between-hosts-and-options – Saif Jun 28 '18 at 21:09
  • Your connection is established you can see your console.log message on the very first line of the message `Connection Successful ...`. – Saif Jun 28 '18 at 21:10
  • Made the change and noticed my error. Thank you. But am now getting an error: name: 'MongoNetworkError', message: 'failed to connect to server [ds121371.mlab.com:21371] on first connect [MongoNetworkError: connect ETIMEDOUT 52.214.93.155:21371]' . By the way inform me if my location could be an issue because from mLab I saw that these services are far away while am in Africa, Kenya. – Eric O. Jun 28 '18 at 21:14
  • 1
    Do you have any special characters like `@` in your password? – Saif Jun 28 '18 at 21:16
  • yeah, I have noted that message but why the other errors? – Eric O. Jun 28 '18 at 21:22
  • 2
    Yeah, my first DB user had a good number of special characters.. but the new one I have created only has a full stop – Eric O. Jun 28 '18 at 21:23
  • Try connecting with some VPN. – Saif Jun 28 '18 at 21:24
  • 1
    Thank you. note I have a low reputation my vote won't count. Meanwhile, kindly check the other errors and suggest for me the possible reasons. – Eric O. Jun 28 '18 at 21:32
  • 1
    You can ask a new question with the new error that you are getting. – Saif Jun 28 '18 at 21:33

1 Answers1

1

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.

Saif
  • 2,530
  • 3
  • 27
  • 45
  • 2
    Just downloaded a VPN software and all is well now. No more errors. – Eric O. Jun 28 '18 at 22:18
  • 1
    I hate asking for it. But you can accept this answer with that tick mark of this solved your question. – Saif Jun 28 '18 at 22:33
  • 1
    Thanks Saif Ur Rahman !! One tip, if I want a secure password I can use https://strongpasswordgenerator.com/ with the "Avoid punctuation used in programming" Marked. – fedeteka Nov 03 '18 at 13:34
  • 1
    @fedeteka It would be better if you don't, because what if they maintain a database of all the random passwords that were generated on their site and later the creator of the website can use that database to perform a dictionary attack on your database. You can create your own strong password similar to the one that you see on strongpasswordgenerator.com but not copying the exact password that you generated with their site. – Saif Nov 04 '18 at 07:29
  • @Saif Ur Rahman I know, but from the website: "This website does not send new passwords across the internet. This website uses JavaScript to generate new passwords here in your browser—feel free to check this webpage’s markup. To stay safe online, make sure that you have upgraded your browser." – fedeteka Nov 04 '18 at 13:13