@@ -994,7 +994,14 @@ working MongoDB connection in your Symfony application as explained in the
994
994
`DoctrineMongoDBBundle configuration `_ article.
995
995
996
996
Then, 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
+
998
1005
999
1006
.. configuration-block ::
1000
1007
@@ -1007,6 +1014,7 @@ the MongoDB connection as argument:
1007
1014
Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler :
1008
1015
arguments :
1009
1016
- ' @doctrine_mongodb.odm.default_connection'
1017
+ - { database: '%env(MONGODB_DB)%', collection: 'sessions' }
1010
1018
1011
1019
.. code-block :: xml
1012
1020
@@ -1022,6 +1030,10 @@ the MongoDB connection as argument:
1022
1030
<services >
1023
1031
<service id =" Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler" >
1024
1032
<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 >
1025
1037
</service >
1026
1038
</services >
1027
1039
</container >
@@ -1039,6 +1051,7 @@ the MongoDB connection as argument:
1039
1051
$services->set(MongoDbSessionHandler::class)
1040
1052
->args([
1041
1053
service('doctrine_mongodb.odm.default_connection'),
1054
+ ['database' => '%env('MONGODB_DB')%', 'collection' => 'sessions']
1042
1055
])
1043
1056
;
1044
1057
};
@@ -1088,13 +1101,6 @@ configuration option to tell Symfony to use this service as the session handler:
1088
1101
;
1089
1102
};
1090
1103
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
1104
That's all! Symfony will now use your MongoDB server to read and write the
1099
1105
session data. You do not need to do anything to initialize your session
1100
1106
collection. 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
1123
1129
Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler :
1124
1130
arguments :
1125
1131
- ' @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'
1127
1137
1128
1138
.. code-block :: xml
1129
1139
@@ -1138,6 +1148,8 @@ configure these values with the second argument passed to the
1138
1148
<service id =" Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler" >
1139
1149
<argument type =" service" >doctrine_mongodb.odm.default_connection</argument >
1140
1150
<argument type =" collection" >
1151
+ <argument key =" database" >%env('MONGODB_DB')%</argument >
1152
+ <argument key =" collection" >sessions</argument >
1141
1153
<argument key =" id_field" >_guid</argument >
1142
1154
<argument key =" expiry_field" >eol</argument >
1143
1155
</argument >
@@ -1158,7 +1170,12 @@ configure these values with the second argument passed to the
1158
1170
$services->set(MongoDbSessionHandler::class)
1159
1171
->args([
1160
1172
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
+ ],
1162
1179
])
1163
1180
;
1164
1181
};
0 commit comments