Reputation: 181
Here is my error captured:
and here are my coding files:
server file
keys file
I just create connection to mlab using mongodb, node and reactjs. I'm using mongo db version 4.
need your help guys.
[nodemon] starting `node server.js`
Error: URL malformed, cannot be parsed
at module.exports (C:\MERNapps\TestMERN08\node_modules\mongodb\lib\url_parser.js:17:21)
at deprecated (internal/util.js:47:15)
at connect (C:\MERNapps\TestMERN08\node_modules\mongodb\lib\operations\mongo_client_ops.js:179:3)
at connectOp (C:\MERNapps\TestMERN08\node_modules\mongodb\lib\operations\mongo_client_ops.js:283:3)
at executeOperation (C:\MERNapps\TestMERN08\node_modules\mongodb\lib\utils.js:420:24)
at MongoClient.connect (C:\MERNapps\TestMERN08\node_modules\mongodb\lib\mongo_client.js:168:10)
at Promise (C:\MERNapps\TestMERN08\node_modules\mongoose\lib\connection.js:493:12)
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (C:\MERNapps\TestMERN08\node_modules\mongoose\lib\connection.js:490:19)
at Mongoose.connect (C:\MERNapps\TestMERN08\node_modules\mongoose\lib\index.js:230:15)
at Object.<anonymous> (C:\MERNapps\TestMERN08\server.js:12:2)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
(node:3696) 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.
server running on port 5000
Upvotes: 3
Views: 4976
Reputation: 307
a very common error with MongoDB atlas. better still follow this procedure
Install Mongo DB compass
use Default setting
hostname: localhost & port 27017
mongoose.connect('mongodb://localhost/projectname') .then(() => console.log('mongo db working')) .catch(err => console.log('ERROR is', err))
Upvotes: 1
Reputation: 1341
The issue is with your keys. Try using:
module.exports= {
mongoURI : "your-uri-string",
options:{key:value}
}
And use the keys as:
mongoose.connect(db.mongoURI,options);
Upvotes: 1