@@ -989,7 +989,14 @@ working MongoDB connection in your Symfony application as explained in the
989
989
`DoctrineMongoDBBundle configuration `_ article.
990
990
991
991
Then, register a new handler service for ``MongoDbSessionHandler `` and pass it
992
- the MongoDB connection as argument:
992
+ the MongoDB connection as argument, and the required parameters:
993
+
994
+ ``database ``:
995
+ The name of the database
996
+
997
+ ``collection ``:
998
+ The name of the collection
999
+
993
1000
994
1001
.. configuration-block ::
995
1002
@@ -1002,6 +1009,7 @@ the MongoDB connection as argument:
1002
1009
Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler :
1003
1010
arguments :
1004
1011
- ' @doctrine_mongodb.odm.default_connection'
1012
+ - { database: '%env(MONGODB_DB)%', collection: 'sessions' }
1005
1013
1006
1014
.. code-block :: xml
1007
1015
@@ -1017,6 +1025,10 @@ the MongoDB connection as argument:
1017
1025
<services >
1018
1026
<service id =" Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler" >
1019
1027
<argument type =" service" >doctrine_mongodb.odm.default_connection</argument >
1028
+ <argument type =" collection" >
1029
+ <argument key =" database" >%env('MONGODB_DB')%</argument >
1030
+ <argument key =" collection" >sessions</argument >
1031
+ </argument >
1020
1032
</service >
1021
1033
</services >
1022
1034
</container >
@@ -1034,6 +1046,7 @@ the MongoDB connection as argument:
1034
1046
$services->set(MongoDbSessionHandler::class)
1035
1047
->args([
1036
1048
service('doctrine_mongodb.odm.default_connection'),
1049
+ ['database' => '%env("MONGODB_DB")%', 'collection' => 'sessions']
1037
1050
])
1038
1051
;
1039
1052
};
@@ -1083,13 +1096,6 @@ configuration option to tell Symfony to use this service as the session handler:
1083
1096
;
1084
1097
};
1085
1098
1086
- .. note ::
1087
-
1088
- MongoDB ODM 1.x only works with the legacy driver, which is no longer
1089
- supported by the Symfony session class. Install the ``alcaeus/mongo-php-adapter ``
1090
- package to retrieve the underlying ``\MongoDB\Client `` object or upgrade to
1091
- MongoDB ODM 2.0.
1092
-
1093
1099
That's all! Symfony will now use your MongoDB server to read and write the
1094
1100
session data. You do not need to do anything to initialize your session
1095
1101
collection. However, you may want to add an index to improve garbage collection
@@ -1118,7 +1124,11 @@ configure these values with the second argument passed to the
1118
1124
Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler :
1119
1125
arguments :
1120
1126
- ' @doctrine_mongodb.odm.default_connection'
1121
- - { id_field: '_guid', 'expiry_field': 'eol' }
1127
+ -
1128
+ database : ' %env(MONGODB_DB)%'
1129
+ collection : ' sessions'
1130
+ id_field : ' _guid'
1131
+ expiry_field : ' eol'
1122
1132
1123
1133
.. code-block :: xml
1124
1134
@@ -1133,6 +1143,8 @@ configure these values with the second argument passed to the
1133
1143
<service id =" Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler" >
1134
1144
<argument type =" service" >doctrine_mongodb.odm.default_connection</argument >
1135
1145
<argument type =" collection" >
1146
+ <argument key =" database" >%env('MONGODB_DB')%</argument >
1147
+ <argument key =" collection" >sessions</argument >
1136
1148
<argument key =" id_field" >_guid</argument >
1137
1149
<argument key =" expiry_field" >eol</argument >
1138
1150
</argument >
@@ -1153,7 +1165,12 @@ configure these values with the second argument passed to the
1153
1165
$services->set(MongoDbSessionHandler::class)
1154
1166
->args([
1155
1167
service('doctrine_mongodb.odm.default_connection'),
1156
- ['id_field' => '_guid', 'expiry_field' => 'eol'],
1168
+ [
1169
+ 'database' => '%env('MONGODB_DB')%',
1170
+ 'collection' => 'sessions'
1171
+ 'id_field' => '_guid',
1172
+ 'expiry_field' => 'eol',
1173
+ ],
1157
1174
])
1158
1175
;
1159
1176
};
0 commit comments