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},{useNewUrlParser:true,useUnifiedTopology:true}).then(()=>{
console.log(‘Db connceted suffuly’)

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

Can you connect to your DB with shell?

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

1 Like

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

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

1 Like

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