@@ -1007,6 +1007,7 @@ the MongoDB connection as argument:
1007
1007
Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler :
1008
1008
arguments :
1009
1009
- ' @doctrine_mongodb.odm.default_connection'
1010
+ - { database: '%env(MONGODB_DB)%', collection: 'sessions' }
1010
1011
1011
1012
.. code-block :: xml
1012
1013
@@ -1022,6 +1023,10 @@ the MongoDB connection as argument:
1022
1023
<services >
1023
1024
<service id =" Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler" >
1024
1025
<argument type =" service" >doctrine_mongodb.odm.default_connection</argument >
1026
+ <argument type =" collection" >
1027
+ <argument key =" database" >%env('MONGODB_DB')%</argument >
1028
+ <argument key =" collection" >sessions</argument >
1029
+ </argument >
1025
1030
</service >
1026
1031
</services >
1027
1032
</container >
@@ -1039,6 +1044,7 @@ the MongoDB connection as argument:
1039
1044
$services->set(MongoDbSessionHandler::class)
1040
1045
->args([
1041
1046
service('doctrine_mongodb.odm.default_connection'),
1047
+ ['database' => '%env('MONGODB_DB')%', 'collection' => 'sessions']
1042
1048
])
1043
1049
;
1044
1050
};
@@ -1088,13 +1094,6 @@ configuration option to tell Symfony to use this service as the session handler:
1088
1094
;
1089
1095
};
1090
1096
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
-
1098
1097
That's all! Symfony will now use your MongoDB server to read and write the
1099
1098
session data. You do not need to do anything to initialize your session
1100
1099
collection. However, you may want to add an index to improve garbage collection
@@ -1123,7 +1122,11 @@ configure these values with the second argument passed to the
1123
1122
Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler :
1124
1123
arguments :
1125
1124
- ' @doctrine_mongodb.odm.default_connection'
1126
- - { id_field: '_guid', 'expiry_field': 'eol' }
1125
+ -
1126
+ database : ' %env(MONGODB_DB)%'
1127
+ collection : ' sessions'
1128
+ id_field : ' _guid'
1129
+ expiry_field : ' eol'
1127
1130
1128
1131
.. code-block :: xml
1129
1132
@@ -1138,6 +1141,8 @@ configure these values with the second argument passed to the
1138
1141
<service id =" Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler" >
1139
1142
<argument type =" service" >doctrine_mongodb.odm.default_connection</argument >
1140
1143
<argument type =" collection" >
1144
+ <argument key =" database" >%env('MONGODB_DB')%</argument >
1145
+ <argument key =" collection" >sessions</argument >
1141
1146
<argument key =" id_field" >_guid</argument >
1142
1147
<argument key =" expiry_field" >eol</argument >
1143
1148
</argument >
@@ -1158,13 +1163,24 @@ configure these values with the second argument passed to the
1158
1163
$services->set(MongoDbSessionHandler::class)
1159
1164
->args([
1160
1165
service('doctrine_mongodb.odm.default_connection'),
1161
- ['id_field' => '_guid', 'expiry_field' => 'eol'],
1166
+ [
1167
+ 'database' => '%env('MONGODB_DB')%',
1168
+ 'collection' => 'sessions'
1169
+ 'id_field' => '_guid',
1170
+ 'expiry_field' => 'eol',
1171
+ ],
1162
1172
])
1163
1173
;
1164
1174
};
1165
1175
1166
1176
These are parameters that you can configure:
1167
1177
1178
+ ``database ``:
1179
+ The name of the database
1180
+
1181
+ ``collection ``:
1182
+ The name of the collection
1183
+
1168
1184
``id_field `` (default ``_id ``):
1169
1185
The name of the field where to store the session ID;
1170
1186
0 commit comments