fbpx

Use of RavenDB and why it was a perfect fit for storing /querying JSON

Use of RavenDB and why it was a perfect fit for storing /querying JSON

Use of RavenDB and why it was a perfect fit for storing /querying JSON

As mentioned in Part I, one of our clients wanted to go beyond general web site statistics and traffic. In this article we will talk about what we did for advanced reporting statistics and how we did it (with code samples).  RavenDB_Image1    Image 1

A windows service downloads data from Google Analytics and inserts it into a RavenDB NoSQL database. This allowed us to create a wide variety of advanced reports. A Windows service was configured to run every night to download daily activity log from Google Analytics site using their download API.

Before you can download the data you need to:

  1. Register your application using Google APIs console .
  2. After you’ve registered, go to the API Access tab and copy the “Client ID” and “Client secret” values, which you’ll need later. Click here to get more info on how to get Client ID and “Client secret” key
  3. Following code snippet shows how to authenticate Google API and call Get method to get data from Google Analytics. RavenDB_Image2 4) Once you have the data as JSON objects next step is to insert it into database. We chose RavenDB to store JSON object for further data processing

Why RavenDB?
RavenDB is a relatively new, open source document database for .NET. As we are storing JSON objects in Google Analytics it made sense to keep data in JSON format and save it in document database. It made retrieval of information fast and easy (more detail below). We had a choice in another popular document database – MongoDB – but we chose RavenDB over MongoDB because:

  • RavenDB is built in C#
  • RavenDB supports batch transaction
  • Optimistic concurrency
  • Supports full-text query
  • Support static and ad-hoc indexes
  • Supports triggers
  • Rest API

Setting up RavenDB: The RavenDB server instance can be instantiated in several ways:

  • Running the Raven.Server.exe console application (located under /Server/ in the build package).
  • Running RavenDB as a service.
  • Integrating RavenDB with IIS on your Windows based server.
  • Embedding the server in your application.

A great source of information on setting up RavenDB database is at:

Retrieving data from RavenDB:

  1. Connection to RavenDB: There are 4 modes to set up RavenDB data source. We configured the RavenDB in server mode. Following code snippet shows how to connect to RavenDB in server mode. RavenDB_Image3.jpg
  2. Querying database to retrieve data: The built-in Linq provider implements the IQueryable interface. This makes it very easy to retrieve data by writing Linq queries. Here is an example of getting all the Companies From RavenDB database using Linq (visit RavenDB knowledge base for more details) RavenDB_Image4.jpg
  3. Creating Custom reports: Criteria for filtering is based on user input and data from the database is accessed and parsed into c# object using Linq queries. Data calculations and graph was generated at runtime. RavenDB_Image5.jpg
  4. Creating graphs: We used Rickshaw toolkit for creating interactive graphs.  RavenDB_Image6.jpg

For the client, we were able to use this data to create Timeline reports by pulling past usage data and comparing it to current data over a variety of time periods for practically every action a user can perform on the site.

Thus, by using JSON and Knockout for binding and Rickshaw toolkit for graphing, we were able to create scalable, customizable and interactive report. RavenDB played a key role by providing us fast and reliable DB source.

Let me know if you have questions or comments on our experience!

References:

  1. Google APIs console
  2. http://ravendb.net/
  3. http://code.shutterstock.com/rickshaw/

Picture cortesy of Gosa Postoronca

Related Blogs

have a question?

Send us a message

stay informed
Subscribe to 2m2x! Get the latest insights on innovation from our CEO, Rajiv Menon

We love making an impact!

To request a call, fill out the form below and an Informulate team member will reach out to discuss your project needs.

Time To Reinvent Your Company?​

Time to reinvent your company but not sure where to start? Download or free Innovation Workbook to get started today!

* You will be automatically redirected to the Workbook after you complete the form.

Process Automation

To learn more about our Process Automation solutions, fill out the form below and an Informulate team member will reach out to discuss your project needs.

Code Review

To learn more about our Code Review, fill out the form below and an Informulate team member will reach out to discuss your project needs.

Process Audit

To learn more about our Process Audit, fill out the form below and an Informulate team member will reach out to discuss your project needs.

AI Workflow Review

To learn more about our AI workflow Review, fill out the form below and an Informulate team member will reach out to discuss your project needs.

Digital Transformation

To learn more about our Digital Transformation solutions, fill out the form below and an Informulate team member will reach out to discuss your project needs.

Product Development

To learn more about our Product Development solutions, fill out the form below and an Informulate team member will reach out to discuss your project needs.

Team Enrichment

To learn more about our Team Enrichment solutions, fill out the form below and an Informulate team member will reach out to discuss your project needs.

Business Intelligence

To learn more about our Business Intelligence solutions, fill out the form below and an Informulate team member will reach out to discuss your project needs.

AI Consulting

To learn more about our AI Consulting solutions, fill out the form below and an Informulate team member will reach out to discuss your project needs.

We are ready to help you succeed!

To request a call, fill out the form below and an Informulate team member will reach out to discuss your project needs.

We love making an impact!

To request a call, fill out the form below and an Informulate team member will reach out to discuss your project needs.

We love making an impact!

To request a call, fill out the form below and an Informulate team member will reach out to discuss your project needs.

We love making an impact!

To request a call, fill out the form below and an Informulate team member will reach out to discuss your project needs.

Digital Transformation

To learn more about our Digital Transformation solutions, fill out the form below and an Informulate team member will reach out to discuss your project needs.

We love making an impact!

To request a call, fill out the form below and an Informulate team member will reach out to discuss your project needs.

Submit Your Resume

To apply for this position, fill out the form below and attach your resume in PDF format. A member of our HR team will review your submission and reply accordingly.

We love building things!

To request a call, fill out the form below and an Informulate team member will reach out to discuss your project needs.