MongooseError:err URI must include hostname, domain name, and tld


I’m trying to build a command-line application without installing MongoDB I am using their cloud database so I try to insert the URL to connect the database I got the above screenshots error
here is my DB connection code:
const db=mongoose.connect(mongodb+srv://${username}:${password}@cluster0.e7euu.mongodb.net/customer_mangement?retryWrites=true&w=majority,{useNewUrlParser:true,useUnifiedTopology:true}).then(()=>{
console.log(‘Db connceted suffuly’)
}).catch((err)=>{console.log(‘err’,err.message)});

//const customer=require(’./modals/customer’)
//Add New Customer
const addCustomer=(customer)=>{
customer.create(customer).then(customer=>{
console.info(customer);
console.info(‘New Customer Added’);
db.close();
})
}
// Find Customer
const findCustomer=(name)=>{
const search=new RegExp(name,i);
Customer.find({$or:[{firstname:search},{lastname:search}]}).then(customer=>{
console.info(customer);
console.info(${customer.length} matches);
db.close();
});
}
//
module.exports={
addCustomer,
findCustomer
}

Can you connect to your DB with shell?

Does your password has any special characters like “#” etc?

3 Likes

yupp i used @ special character in password
i choose connect with app link is it not used in cli application

1 Like

You have to escape the special characters with %encoding or change your password to a simple one or use encodeURIComponent in the connect string

4 Likes

This topic was automatically closed after 180 days. New replies are no longer allowed.