Connect mongodb atlas - symfony local web server

Trying since days to connect mongodb atlas to symfony project using MongoDB php extension and MongoDB PHP Driver + mongodb-odm-bundle for Symfony,

here are the main files


###> doctrine/mongodb-odm-bundle ###



###< doctrine/mongodb-odm-bundle ###


    auto_generate_proxy_classes: true
    auto_generate_hydrator_classes: true
            server: '%env(resolve:MONGODB_URL)%'
            options: {}
    default_database: '%env(resolve:MONGODB_DB)%'
            auto_mapping: true
                    dir: '%kernel.project_dir%/src/Document'
                    prefix: 'App\Document'
                    mapping: true
                    type: attribute
                    is_bundle: false
                    alias: App

        auto_generate_proxy_classes: false
        auto_generate_hydrator_classes: false
                    type: service
                    id: doctrine_mongodb.system_cache_pool

                    adapter: cache.system


# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

# Put parameters here that don't need to change on each machine where the app is deployed
    env(MONGODB_URL): ''
    env(MONGODB_DB): ''

    # default configuration for services in *this* file
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
        resource: '../src/'
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'

    # add more service definitions when explicit configuration is needed
    # please note that last definitions always *replace* previous ones
        public: true



namespace App\Service;

use MongoDB\Client;

class MongoDbClient
    private $client;

    public function __construct()
        $uri = 'mongodb+srv://';

        $options = [
            'serverApi' => [
                'version' => 1,
                'strict' => true,

        $this->client = new Client($uri, $options);

    public function getClient()
        return $this->client;



namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use App\Service\MongoDbClient;

class DefaultController extends AbstractController
    private $mongoDBClient;

    public function __construct(MongoDbClient $mongoDBClient)
        $this->mongoDBClient = $mongoDBClient;

    public function index(): Response
        $client = $this->mongoDBClient->getClient();

        try {
            $client->selectDatabase('sample_training')->command(['ping' => 1]);
            $message = "Pinged your deployment. You successfully connected to MongoDB!";
        } catch (\Exception $e) {
            $message = $e->getMessage();

        return new Response($message);

got this error message on the terminal,

emericp@mbp-de-emeric monprojet % symfony server:log
Following Web Server log file (/Users/emericp/.symfony5/log/9e98f4d5ef0deaa3b24ff7a1f87a25093c924fcc.log)
Following PHP-FPM log file (/Users/emericp/.symfony5/log/9e98f4d5ef0deaa3b24ff7a1f87a25093c924fcc/53fb8ec204547646acb3461995e4da5a54cc7575.log)
[Web Server ] Apr 21 22:42:47 |ERROR  | SERVER GET  (500) /maroute ip=""
[PHP-FPM    ] [21-Apr-2024 20:42:47 UTC] [critical] Uncaught Exception: Failed to parse URI options: Failed to look up SRV record "": A temporary error occurred on an authoritative name server. Try again later.

hope someone have a clue on what’s happening here …

Hi @Emeric_Petitgenet

Welcome to MongoDB forums!

From the error message, it seems to be a DNS issue - the SRV record resolution is failing. Please check your DNS configuration. You can try to perform a nslookup to manually check DNS resolution.

Additionally, you can cross check by connecting to your Atlas cluster with the same URI on the same machine, via mongosh or MongoDB Compass.

We also published a MongoDB Atlas + Symfony step by step tutorial that should help you as well -

Hi @Rishabh_Bisht ,

thank you for responding ! here what I can say,

  • I can connect from compass it’s working fine
  • I tried to follow step by step rental tutorial and facing the same problem
  • I only struggle with the connexion within symfony project

here is the result of nslookup

me@me ~ % nslookup -type=SRV

Server: 2a01:cb15:8020:6900:3e58:5dff:fe0d:12c1

Address: 2a01:cb15:8020:6900:3e58:5dff:fe0d:12c1#53

Non-authoritative answer: service = 0 0 27017


Authoritative answers can be found from:

no authoritative answers


I’d like to confirm if it’s really a DNS issue. Can you try switching to seedlist URI and see if it works?

In the connection URI dialog in Atlas, change the driver to an older version to get the seed list URI and try using that in your Symfony application.
Screenshot 2024-04-24 at 3.55.43 PM

Hi @Rishabh_Bisht ,

tried several drivers including PHPLIB.1.1 + mongodb-1.2 or later, it didn’t help neither datas to understand what is going on

I join a screenshot, this is literally what I’m facing with each time I use connection string launching Symfony local web server. No response / error message , juste stuck somewhere between request and answer
Capture d’écran 2024-04-24 à 13.53.58

may this information help : asked someone to clone my github repository, so with the same project and same command, this guy can run the code with no difficulty