Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

820
Views
MongoDB Docker URI does not have hostname, domain name and tld

I am trying to connect to my local MongoDB Database that is on docker with nodejs. My component are:

.env file

MONGODB_USERNAME = 'accountUser'
MONGODB_PASSWORD = 'password'
MONGODB_HOST = 'mongodb'
MONGODB_DATABASE = 'mydb'

Code:

const uri = `mongodb+srv://${process.env.MONGODB_USERNAME}:${process.env.MONGODB_PASSWORD}@${process.env.MONGODB_HOST}/${process.env.MONGODB_DATABASE}?retryWrites=true&w=majority`;

    console.log(uri);

    const client = new MongoClient(uri);

Console Output

mongodb+srv://accountUser:abc123@mongodb/mydb?retryWrites=true&w=majority

Error

MongoParseError: URI does not have hostname, domain name and tld

What can I be doing wrong?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You are trying to use an SRV URI when you should be using an ordirary URI.

SRV URIs have the additional security requirements on hostnames (that it contains 3 components minimum).

Remove +srv from your URI.

over 4 years ago · Santiago Trujillo Report

0

1). Go to the database, click edit password and generate a new password.
2). Go to the database, click edit password and give only characters and numbers.

over 4 years ago · Santiago Trujillo Report

0

How to connect to MongoDB Atlas from a NestJS Application:

  1. Under Deployment select Databases
  2. Click on your database instance
  3. Next to the name and status of the instance click Connect
  4. Click Connect your application
  5. Under DRIVER select Node.js
  6. Under VERSION select 2.2.12 or later
  7. Copy the full URI including all of the individual nodes and use that to connect instead

As D. SM said earlier you can't use a URI with +srv in it and rolling back the driver version is the only way to get a connection string generated without +srv.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!