DEV Community

Cover image for How to fix - UnhandledPromiseRejectionWarning: MongoParseError: URI does not have hostname, domain name and tld
Mamun Abdullah
Mamun Abdullah

Posted on

How to fix - UnhandledPromiseRejectionWarning: MongoParseError: URI does not have hostname, domain name and tld

A solution for MongoParseError (UnhandledPromiseRejectionWarning: MongoParseError: URI does not have hostname, domain name and tld... )

(node:2436) UnhandledPromiseRejectionWarning: MongoParseError: URI does not have hostname, domain name and tld
    at parseSrvConnectionString (E:\mern\mongo-office\backend\node_modules\mongodb\lib\core\uri_parser.js:45:21)
    at parseConnectionString (E:\mern\mongo-office\backend\node_modules\mongodb\lib\core\uri_parser.js:587:12)
    at connect (E:\mern\mongo-office\backend\node_modules\mongodb\lib\operations\connect.js:282:3)
    at E:\mern\mongo-office\backend\node_modules\mongodb\lib\mongo_client.js:223:5
    at maybePromise (E:\mern\mongo-office\backend\node_modules\mongodb\lib\utils.js:662:3)
    at MongoClient.connect (E:\mern\mongo-office\backend\node_modules\mongodb\lib\mongo_client.js:219:10)
    at E:\mern\mongo-office\backend\node_modules\mongoose\lib\connection.js:791:12
    at new Promise (<anonymous>)
    at NativeConnection.Connection.openUri (E:\mern\mongo-office\backend\node_modules\mongoose\lib\connection.js:788:19)
    at E:\mern\mongo-office\backend\node_modules\mongoose\lib\index.js:342:10
    at E:\mern\mongo-office\backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:5
    at new Promise (<anonymous>)
    at promiseOrCallback (E:\mern\mongo-office\backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:30:10)
    at Mongoose.connect (E:\mern\mongo-office\backend\node_modules\mongoose\lib\index.js:341:10)
    at Object.<anonymous> (E:\mern\mongo-office\backend\server.js:11:10)
    at Module._compile (internal/modules/cjs/loader.js:1076:30)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2436) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:2436) [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.

Enter fullscreen mode Exit fullscreen mode

If you think everything in your MONGO_URI is ok but face this problem with mongoDB connection,

you can simply solve this issue by following these steps:

Check your MONGO_URI in .env file if your password has any special character like #, @, ! and so on.

If found, just change your password from the MongoDB account for that database username and make it without those characters. Use the new password to your MONGO_URI.

The problem is solved! Now run the server again.

Top comments (0)