How to get specific document manager in controller?

Viewed 181

I configured and two document managers, each document manager responsible for particular DB

File location: /config/packages/doctrine_mongodb.yaml

doctrine_mongodb:
    auto_generate_proxy_classes: true
    auto_generate_hydrator_classes: true
    connections:
        default:
            server: '%env(resolve:MONGODB_URL)%'
            options: {}
    default_database: '%env(resolve:MONGODB_DB)%'
    document_managers:
        default:
            auto_mapping: true
            mappings:
                App:
                    is_bundle: false
                    type: annotation
                    dir: '%kernel.project_dir%/src/Document'
                    prefix: 'App\Document'
                    alias: App
        meteo:
            database: '%env(resolve:MONGODB_DB_METEO_NAME)%'

How can I get meteo datamanager in controller?

1 Answers

All document managers are available in the container under the name doctrine_mongodb.odm.%s_document_manager where %s is your manager's name (default/meteo). You need to wire your controller manually and tell Symfony which document manager should be injected.

Related