@@ -994,7 +994,14 @@ working MongoDB connection in your Symfony application as explained in the
994994`DoctrineMongoDBBundle configuration `_ article.
995995
996996Then, register a new handler service for ``MongoDbSessionHandler `` and pass it
997- the MongoDB connection as argument:
997+ the MongoDB connection as argument, and the required parameters:
998+
999+ ``database ``:
1000+ The name of the database
1001+
1002+ ``collection ``:
1003+ The name of the collection
1004+
9981005
9991006.. configuration-block ::
10001007
@@ -1007,6 +1014,7 @@ the MongoDB connection as argument:
10071014 Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler :
10081015 arguments :
10091016 - ' @doctrine_mongodb.odm.default_connection'
1017+ - { database: '%env(MONGODB_DB)%', collection: 'sessions' }
10101018
10111019 .. code-block :: xml
10121020
@@ -1022,6 +1030,10 @@ the MongoDB connection as argument:
10221030 <services >
10231031 <service id =" Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler" >
10241032 <argument type =" service" >doctrine_mongodb.odm.default_connection</argument >
1033+ <argument type =" collection" >
1034+ <argument key =" database" >%env('MONGODB_DB')%</argument >
1035+ <argument key =" collection" >sessions</argument >
1036+ </argument >
10251037 </service >
10261038 </services >
10271039 </container >
@@ -1039,6 +1051,7 @@ the MongoDB connection as argument:
10391051 $services->set(MongoDbSessionHandler::class)
10401052 ->args([
10411053 service('doctrine_mongodb.odm.default_connection'),
1054+ ['database' => '%env('MONGODB_DB')%', 'collection' => 'sessions']
10421055 ])
10431056 ;
10441057 };
@@ -1088,13 +1101,6 @@ configuration option to tell Symfony to use this service as the session handler:
10881101 ;
10891102 };
10901103
1091- .. note ::
1092-
1093- MongoDB ODM 1.x only works with the legacy driver, which is no longer
1094- supported by the Symfony session class. Install the ``alcaeus/mongo-php-adapter ``
1095- package to retrieve the underlying ``\MongoDB\Client `` object or upgrade to
1096- MongoDB ODM 2.0.
1097-
10981104 That's all! Symfony will now use your MongoDB server to read and write the
10991105session data. You do not need to do anything to initialize your session
11001106collection. However, you may want to add an index to improve garbage collection
@@ -1123,7 +1129,11 @@ configure these values with the second argument passed to the
11231129 Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler :
11241130 arguments :
11251131 - ' @doctrine_mongodb.odm.default_connection'
1126- - { id_field: '_guid', 'expiry_field': 'eol' }
1132+ -
1133+ database : ' %env(MONGODB_DB)%'
1134+ collection : ' sessions'
1135+ id_field : ' _guid'
1136+ expiry_field : ' eol'
11271137
11281138 .. code-block :: xml
11291139
@@ -1138,6 +1148,8 @@ configure these values with the second argument passed to the
11381148 <service id =" Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler" >
11391149 <argument type =" service" >doctrine_mongodb.odm.default_connection</argument >
11401150 <argument type =" collection" >
1151+ <argument key =" database" >%env('MONGODB_DB')%</argument >
1152+ <argument key =" collection" >sessions</argument >
11411153 <argument key =" id_field" >_guid</argument >
11421154 <argument key =" expiry_field" >eol</argument >
11431155 </argument >
@@ -1158,7 +1170,12 @@ configure these values with the second argument passed to the
11581170 $services->set(MongoDbSessionHandler::class)
11591171 ->args([
11601172 service('doctrine_mongodb.odm.default_connection'),
1161- ['id_field' => '_guid', 'expiry_field' => 'eol'],
1173+ [
1174+ 'database' => '%env('MONGODB_DB')%',
1175+ 'collection' => 'sessions'
1176+ 'id_field' => '_guid',
1177+ 'expiry_field' => 'eol',
1178+ ],
11621179 ])
11631180 ;
11641181 };
0 commit comments