I'm trying to connect MongoDB with node.js, but the terminal is showing MongoAPIError: URI must include hostname, domain name, and tld
I have written monogoDB code in a database file and added/required the file path in the backend file
const express = require("express");
const app = express();
const dotenv = require("dotenv");
const path = require('path');
const bcrypt = require('bcrypt');
dotenv.config({path: './config.env'})
require('./database-connection.js')
const port = 80
Database connection file name: database-connection.js
const mongoose = require("mongoose");
const db = mongodb+srv://kumbamshyam:Superman@[email protected]/ecommerce-website?retryWrites=true&w=majority
mongoose.connect(db).then(()=>{
console.log('conencted successfuly');
}).catch((err)=>{
console.log("Error received= " + err)
})
Error received= MongoAPIError: URI must include hostname, domain name, and tld
Any solution for this problems
Probably it's because you've used the special character "@" in your password, and a character like this "must be converted using percent encoding" (https://docs.mongodb.com/manual/reference/connection-string/#examples).
Use the percent sign followed by the HEX code of the special character you've used (i.e., the number 40).
So, your password must be written this way: Superman%40123
I solve this error by removing special characters from my password MongoDB User. Hope this works for you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With