By default, Session stores session data in a collection named 'session' inside the default database.
This collection is better to be pre-created with fields 'id' and 'expire' indexed.
The collection name can be changed by setting [[sessionCollection]].
The following example shows how you can configure the application to use Session:
Add the following to your application config under components:
php
'session' => [
'class' => 'yii\mongodb\Session',
'db' => 'mymongodb',
'sessionCollection' => 'my_session',
]
Session extends [[MultiFieldSession]], thus it allows saving extra fields into the [[sessionCollection]].
Refer to [[MultiFieldSession]] for more details.
Tip: you can use MongoDB TTL index for the session garbage
collection for performance saving, in this case you should set [[Session::gCProbability]] to 0.