Reputation: 656
Using following code to connect:
mongoose.connect(dbConnection, dbOptions, function (err, res) {
if (err) {
console.log('ERROR connecting to: ' + dbConnection + '. ' + err);
} else {
console.log('Successfully connected to: ' + dbConnection);
}
});
But Unable to connect getting following error:
URIError: URI malformed
Please help me to resolve this. Thanks in advance..
Upvotes: 0
Views: 2591
Reputation: 4035
The problem is that (from connection string spec):
If the username, or password section contains a percent sign ("
%
"), an at-sign ("@
") or a colon (":
") it MUST be URL encoded.If the user information contains an at-sign ("@") or more than one colon ("
:
") then an exception MUST be thrown informing the user that the username and password must be URL encoded.
try with encodeURIComponent()
Upvotes: 4
Reputation: 515
This is most likely not related to mongoose. It could be the specified HOST parameter that has a malformed URL, or the error is caused by another section of code.
Upvotes: 0