Error connecting MongoDB with Symfony 5.2

Viewed 405

I am trying create a database using MongoDB in my Symfony 5.2

When I add in my .env this

###> doctrine/mongodb-odm-bundle ###
MONGODB_URL=mongodb://localhost:27017
MONGODB_DB=symfony
###< doctrine/mongodb-odm-bundle ###

with the DATABASE_URL var by default (if I change postgresql to mongodb, it says driver not found)

DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"

I have this error

Connection does not contain a 'path' or 'dbname' parameter and cannot be created.

If I comment the var DATABASE_URL. I got

Environment variable not found: "DATABASE_URL"

My doctrine_mongodb.yaml:

#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)%'

I am executing this command php bin/console doctrine:database:create

I didn't see many solutions for this trouble here

0 Answers
Related