Sitecore xDB – flush data to MongoDB

When debugging Sitecore xDB issues, it is a pain that data is not written to MongoDB directly, but you have to wait for your session to end.

The legend said that you could either set the session timeout to 1 minute, or call Session.Abandon() to write to MongoDB. None of this have ever worked for me, until my colleague Lasse Pedersen found the final, bullet-proof way of having the xDB session data written to MongoDB.

Create a page with the following contents, and call it when you wish to flush data from xDB to MongoDB:


We will all pray to the debugging gods that this fix will work in every scenario.

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in c#, General .NET, Sitecore 8 and tagged , , , . Bookmark the permalink.

5 Responses to Sitecore xDB – flush data to MongoDB

  1. nickhillstc says:

    When testing something similar I found sometimes Sitecore would abort the commitSession pipeline due to either thinking I was a robot or having no pages (IgnoreVisitsWithoutPages).

    I’ve not had issues with the minute timeout but would happily speed up the wait with the example above :)


  2. jammykam says:

    Interestingly EndVisit() was temperamental for me, but Session.Abandon() worked :)

    With regards to robots, update the setting to false to not detect:


  3. Stefan Sluijter says:

    Hello Brian,

    We use FlushContactToXdb2 and seems to be flawless so far.

    public Contact Flush()
    return this.contactManager?.FlushContactToXdb2(this.Contact);

    Let me know if this works out the same =)


  4. Pingback: Sitecore MongoDB – What do we know about a contact? | Brian Pedersen's Sitecore and .NET Blog

  5. Örvar says:

    You are the man Brian!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.