Skip to content

Commit

Permalink
Add new config value to tests, add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
maschmann committed Dec 28, 2016
1 parent 503456f commit 533e1f5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Resources/doc/config.rst
Expand Up @@ -387,6 +387,50 @@ string as a comma separated list.
Where mongodb-01, mongodb-02 and mongodb-03 are the machine hostnames. You
can also use IP addresses if you prefer.

Using Authentication on a Database Level
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MongoDB supports authentication and authorisation on a database-level. This is mandatory if you have
e.g. a publicly accessible MongoDB Server. To make use of this feature you need to configure credentials
for each of your connections. Also every connection needs a database set to authenticate against. The setting is
represented by the *authSource* `connection string <https://docs.mongodb.com/manual/reference/connection-string/#urioption.authSource>`_.
Otherwise you will get a *auth failed* exception.

.. configuration-block::

.. code-block:: yaml
doctrine_mongodb:
# ...
connections:
default:
server: "mongodb://localhost:27017"
username: someuser
password: somepass
authSource: db_you_have_access_to
.. code-block:: xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:doctrine="http://symfony.com/schema/dic/doctrine/odm/mongodb"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/doctrine/odm/mongodb http://symfony.com/schema/dic/doctrine/odm/mongodb/mongodb-1.0.xsd">
<doctrine:mongodb>
<doctrine:connection id="default" server="mongodb://localhost:27017"/>
<doctrine:options
username="someuser"
password="somepass"
authSource="db_you_have_access_to"
>
</doctrine:options>
</doctrine:connection>
</doctrine:mongodb>
</container>
Retrying Connections and Queries
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -446,6 +490,7 @@ Full Default Configuration
connect: ~
connectTimeoutMS: ~
db: ~
authSource: ~
journal: ~
password: ~
readPreference: ~
Expand Down Expand Up @@ -524,6 +569,7 @@ Full Default Configuration
connect=""
connectTimeoutMS=""
db=""
authSource=""
journal=""
password=""
readPreference=""
Expand Down
1 change: 1 addition & 0 deletions Tests/DependencyInjection/ConfigurationTest.php
Expand Up @@ -102,6 +102,7 @@ public function testFullConfiguration($config)
'socketTimeoutMS' => 1000,
'ssl' => true,
'authMechanism' => 'X509',
'authSource' => 'some_db',
'username' => 'username_val',
'w' => 'majority',
'wTimeoutMS' => 1000,
Expand Down
1 change: 1 addition & 0 deletions Tests/DependencyInjection/Fixtures/config/xml/full.xml
Expand Up @@ -36,6 +36,7 @@
connect="true"
connectTimeoutMS="500"
db="database_val"
authSource="some_db"
journal="true"
password="password_val"
readPreference="secondaryPreferred"
Expand Down
1 change: 1 addition & 0 deletions Tests/DependencyInjection/Fixtures/config/yml/full.yml
Expand Up @@ -30,6 +30,7 @@ doctrine_mongodb:
options:
connect: true
connectTimeoutMS: 500
authSource: some_db
db: database_val
journal: true
password: password_val
Expand Down

0 comments on commit 533e1f5

Please sign in to comment.