Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

surfweb's avatar

Mongodb: Failed to parse URI options: Failed to look up SRV record

Hi.

I am using laravel homestead and was able to configure almost everything I needed.

I am experiencing this problem: I installed the php driver to connect with mongodb and tried to create a small project in laravel by adding the jenssegers/mongodb library.

The mongodb database is on the atlas servers.

I entered the string that allows me to connect to the database like this:

new MongoDB\Client('mongodb+srv://user:[email protected]')

If I try to connect I get this error:

Fatal error: Uncaught MongoDB\Driver\Exception\InvalidArgumentException: Failed to parse URI options: Failed to look up SRV record "_mongodb._tcp.db.7h4dt.mongodb.net": The requested name is valid but does not have an IP address. 

I have tried the same configuration on a digital ocean server and I do not encounter any problems.

Can anyone help me solve the problem?

Thanks

0 likes
8 replies
surfweb's avatar

@Sinnbeck thanks for reply.

I tried that way too but I get this other error:

Fatal error: Uncaught MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found (`serverSelectionTryOnce` set): [Failed to resolve 'db.7h4dt.mongodb.net']
surfweb's avatar

@Sinnbeck Before I wrote I had googled and had already come to the link you pointed to, so I had already tried to do what you wrote.

Here the complete query taken from the atlas server:

new MongoDB\Client('mongodb://user:[email protected]/?retryWrites=true&w=majority')

Unfortunately, it doesn't work.

Sinnbeck's avatar

@surfweb maybe try posting on the official Mongodb forum as well? Might help your chances of getting a reply :)

My guess is that it's a problem with virtualbox, but as I don't use that myself I cannot really give a solution

surfweb's avatar

@Sinnbeck Thank you very much for the support.

I also tried to install virtualmin on ubuntu with virtualbox and I have no problem connecting to mongodb.

I will try to ask the mongodb support forum as well.

Thank you

thunderclap's avatar

In my case, the password includes the special characters, and after converted them by using percent-encoding, it's worked

surfweb's avatar

@thunderclap Hi.

I thank you for your comment. In my case the password contains only letters and numbers.

Please or to participate in this conversation.