Friday, June 5, 2015

Starting with Sitecore Analytics MongoDB API

I see a lot of questions about how to start using it, so this is a short post about.
For example let's get all Visits data for the last month (last 30 days) for our particular site. First of all we need to get the MongoDB collection named "Interactions" it has all Visits data:

//Connecting to the Analytics DB
var driver = Sitecore.Analytics.Data.DataAccess.MongoDb.MongoDbDriver.FromConnectionString("analytics");

//Building our query
var builder = new QueryBuilder();
var filter = builder.And(builder.GTE(_ => _.StartDateTime, DateTime.Now.AddDays(-30)), builder.EQ(_ => _.SiteName, siteName.ToLower())); 

//Retrieving data from the "Interactions" collection
var interactions = driver.Interactions.FindAs(filter)

In similar way you can get other data.

That is it! 


  1. Its nice to look into your valuable thoughts.I am very much inspired by your blog.So I look forward to see some more updates on your site.

    Hire Mean Stack Developer

  2. We are also pulling the data in the way you have mentioned. I am currently struggling with syntax. Can you please check if you can help me with this question

  3. Thank you for sharing wonderful information with us to get some idea about it.
    Sitecore Training
    Sitecore Online Training
    Sitecore Training in Hyderabad