Walkthrough: Configuring a private session state database using the MongoDB provider

Current version: 8.2

In private session state, all data related to a specific interaction, such as viewed pages, converted goals, triggered campaigns, or accumulated engagement points, is collected and saved to the session state database.

You can use either MongoDB or SQL Server as your private session state store. SQL Server might be an appropriate option if you are running the collection database (MongoDB) in the cloud as a service, or if you prefer not to run an on-premise MongoDB server instance.

This walkthrough describes how to use a MongoDB database as your private session state store using the Sitecore ASP.NET Session State Provider for MongoDB:

Note

If you are using a MongoDB session provider, all content delivery servers should use the same provider pointing to the same database.

Before you deploy MongoDB as your session database consider the impact that it will have on performance.

Deploy a MongoDB session database

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:

    RequestResponse
    <add name="session" connectionString="mongodb://_mongo_server_name_:_port_number_/_session_database_name_" />
  3. The add name value can be session or sharedsession depending on whether you are configuring private or shared session state.

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

  5. Save your changes.

Configure Sitecore

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

  1. In your site root folder <sitename>\Website, open the web.config file and locate the sessionState section:

    RequestResponse
    <sessionState mode="InProc" cookieless="false" timeout="20">
  2. Update the sessionState section to use the MongoDB provider instead of InProc as shown in the following example. Also, change the name attribute value to mongo:

    RequestResponse
    <sessionState mode="Custom" customProvider="mongo" cookieless="false" timeout="20">
      <providers>
        <add name="mongo"
             type="Sitecore.SessionProvider.MongoDB.MongoSessionStateProvider,
             Sitecore.SessionProvider.MongoDB"
             connectionStringName="session"
             pollingInterval="2"
             compression="true"
             sessionType="private"/>
      </providers>
    </sessionState>

Adjust session state settings

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

Setting

Description

connectionStringName

Contains the connection string that Sitecore uses to connect to the session database.

Edit to specify the session state database that you want to use. In the xDB, this database is called session.

For example:

connectionStringName="session"

pollingInterval

Specifies the time interval in seconds that the session-state provider uses to check if any sessions have expired.

For example:

pollingInterval="2"

compression

Indicates that you want session-state data to be compressed.

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:

compression="true"

sessionType

Indicates whether the type of session state is private or shared.

For example:

sessionType="private"

If you have configured everything correctly, a session database should appear in your list of MongoDB databases after the first web request.

Do you have some feedback for us?

If you have suggestions for improving this article,