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! 

7 comments:

  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

    ReplyDelete
  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 http://stackoverflow.com/questions/41566104/issue-with-querying-data-from-mongo-for-nested-elements

    ReplyDelete
  3. hanks for sharing amazing information.Gain the knowledge and hands-on experience

    Mongodb Training in Bangalore

    ReplyDelete
  4. Thanks for Share Such a Awesome Article about Sitecore Training

    ReplyDelete
  5. nice information I found some MongoDB interview questions that s good for MongoDB courses For skilled and creative IT professionals

    ReplyDelete
  6. I've been looking for the right AWS course to kickstart my cloud journey, and your blog post has helped me narrow down my options. The insights on course content and certification pathways are invaluable. Please visit our website:- aws course

    ReplyDelete