---
title: "Walkthrough: Configuring a shared session state database using the MongoDB provider"
slug: "walkthrough--configuring-a-shared-session-state-database-using-the-mongodb-provider"
abstract: "How to use MongoDB as your shared session state store."
---
# Walkthrough: Configuring a shared session state database using the MongoDB provider

A contact can make multiple visits to a website from different devices or browser sessions at the same time. With shared session-state [the session state database](https://doc.sitecore.com/xp/en/developers/91/platform-administration-and-architecture/scaling-and-configuring-session-state.html "Scaling and configuring session state") collects all the data that can be shared across these multiple sessions. This includes, for example, data related to contacts and devices. This data is still private to the contact but it is accessible from all current sessions made by the same contact.

You must always configure shared session state on your content delivery (CD) servers, regardless of whether you have a single standalone CD server, multiple CD servers, or a clustered environment.

> [!note]
> Shared session state is not supported on content management servers.

You can configure shared session state to use any session-state store provider that extends the abstract class `SessionStateStoreProviderBase `(shipped with ASP.NET). The only additional requirement is that the session-state store provider can invoke the `SessionEnd `event via `SessionStateItemExpireCallback`.

> [!note]
> The standard `OutOfProcSessionStateStore` that is shipped with ASP.NET does not support the `SessionEnd` event and therefore cannot be used with shared session state.
>
> If you are using the xDB Cloud Edition, using the shared session state provider for MongoDB is not included as part of this service.

Follow the steps in this section to use a MongoDB database as your shared session state store using the *Sitecore ASP.NET Session State Provider for MongoDB* deploy a MongoDB session database, configure Sitecore, adjust session state settings.

<details>
<summary><h2>Deploy a MongoDB session database</h2></summary>

The Sitecore ASP.NET Session State Provider for MongoDB enables you to use MongoDB as your session state store. The provider supports the `SessionEnd `event, which the xDB needs to track website visits.

To deploy a MongoDB session database:

1. Install the MongoDB database server version 2.6 or later on a dedicated server using the instructions on the MongoDB website.
2. In a suitable XML editor, open the `ConnectionStrings.config` file located here: `<sitename>\Website\App_Config` and add the following connection string:

    ```text
    <add name="sharedsession" connectionString="mongodb://_mongo_server_name_:_port_number_/_session_database_name_" />
    ```

3. Configure the connection string so that it points to your session database.
4. Save your changes.

</details>

<details>
<summary><h2>Configure Sitecore</h2></summary>

> [!note]
> Do not make changes directly to the configuration files. Instead, you must create a [patch file](https://doc.sitecore.com/xp/en/developers/91/platform-administration-and-architecture/use-a-patch-file-to-customize-the-sitecore-configuration.html "Use a patch file to customize the Sitecore configuration") that performs the required changes during run time.

To configure Sitecore to use the shared session-state provider for MongoDB:

1. In your website root folder, navigate to the `\App_Config\Marketing.Tracking` folder.
2. Open the `Sitecore.Analytics.Tracking.config` file.
3. Locate the line where you can define the default shared session state provider using the following path: `sitecore/tracking/sharedSessionState`.
4. The default shared session store uses inProc provider (storing data in memory and implemented in the internal ASP.NET class InProcSessionStateStore):

    ```xml
    <sharedSessionState defaultProvider="inProc">
      <providers>
        <clear/>
        <add name="inProc" type="System.Web.SessionState.InProcSessionStateStore" />
      </providers>
    </sharedSessionState>
    ```

    > [!note]
    > For clustered environments, Sitecore ships with a MongoDB session state store provider.

5. To configure MongoDB as your shared session-state store provider, change the `defaultProvider` from `inProc` to `mongo`. Also, change the name attribute value to `mongo`.

    ```xml
    <sharedSessionState defaultProvider="mongo">
      <providers>
        <clear/>
        <add name="mongo"
             type="Sitecore.SessionProvider.MongoDB.MongoSessionStateProvider,
             Sitecore.SessionProvider.MongoDB"
             connectionStringName="sharedsession"
             pollingInterval="2"
             compression="true"
             sessionType="shared"/>
      </providers>
    </sharedSessionState>
    ```

</details>

<details>
<summary><h2>Adjust session state settings</h2></summary>

In Sitecore, when you configure a session state, you have the following configuration options:

| Setting | Description | Value |
| --- | --- | --- |
| `connectionStringName` | Specifies the connection string that Sitecore uses to connect to the session database.<br><br>Edit to specify the session state database that you want to use. | For example:<br><br>`connectionStringName="sharedsession"` |
| `pollingInterval` | Specifies the time interval in seconds that the session-state provider uses to check if any sessions have expired. | For example:<br><br>`pollingInterval="2"` |
| `compression` | Specifies that you want session-state data to be compressed.<br><br>The default value is true. Compressing session state data reduces the amount of data that you need to transfer between the database and the Sitecore instance. This may cause some additional CPU overhead. | For example:<br><br>`compression="true"` |
| `sessionType` | Specifies that the type of session state is `shared`. | Only valid value:<br><br>`sessionType="shared"` |

</details>