-
-
Notifications
You must be signed in to change notification settings - Fork 117
fix: Remove incorrect authSource
param from MONGODB_URL
environment variable
#458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@alcaeus Can you confirm that this is the right thing to do? |
I see why not defining the authSource might make sense. Regarding the main database I'm not sure to understand why we should not define it. Because if I get that correctly this means this will make any user of mongodb required to explicitly specify it in Doctrine's configuration, right? |
I think it might also be interesting to ping @quentint who initially contributed the addition of the |
👋 @alcaeus is on holiday so @GromNaN summoned me instead.
What is the purpose of
With respect to the PHP driver, there is no notion of a "default database" and it'd be helpful to only consider an "auth database" (with preference given to the That said, some other drivers/libraries may still infer a default database from the "path" component in the URI (see mongodb/mongo-php-driver#1470 (comment) for more context on that); however, this isn't relevant to Doctrine ODM. According to In the absence of specifying a database name in the model metadata, ODM relies on
I see no reason to specify Some other thoughts: I don't understand what the I also don't understand what the other environment variables are used for. Going back to my original question about |
This fix aims to address the issue with the incorrect MongoDB connection string specified in the
MONGODB_URL
environment variable, as generated by the CLI. #451Consider a Docker Compose configuration for a MongoDB service as follows:
This setup results in the
symfony var:export
command generating aMONGODB_URL
environment variable similar to:Such a configuration typically leads to authentication failures for most applications attempting to connect to MongoDB.
To address this, I have chosen to omit the "path" portion of the connection string entirely, rather than merely replacing
/authSource=symfony
with/symfony
. The latter approach would not resolve the underlying issue. In MongoDB connection strings, specifying a default working database in the URL path (e.g.,mongodb://user:pass@127.0.0.1:27017/defaultDb
) usesdefaultDb
as both the default and authentication database. This behavior is often unintended. To correctly designate separate databases for default operations and authentication, theauthSource
parameter must be explicitly added (e.g.,mongodb://user:pass@127.0.0.1:27017/defaultDb?authSource=authDb
). However, this necessitates the declaration of anauthSource
database within the Docker Compose configuration. I propose avoiding this complication entirely, as both the default database and theauthSource
can be separately specified through dedicated options (e.g., in Doctrine) without embedding them in the connection string.