MongoDB Aggregation Framework inside Countly

Post on 18-Jan-2017

200 views 1 download

Transcript of MongoDB Aggregation Framework inside Countly

1

MongoDB Aggregation in Countly

Agenda

web: count.ly twitter: @gocountly 2

1. MongoDB aggregation framework

overview

2. Short Countly overview3. Two real scenarios where aggregation

framework is used in CountlyWaiter Zen

Software Developer @Countly

MongoDB Aggregation

web: count.ly twitter: @gocountly 3

• MongoDB Aggregation is a framework designed to process data in a declarative and native way using a powerful yet easy to use interface.

• Documents enter a multi-stage pipeline that transforms the documents into an aggregated result.

• As of MongoDB 3.2 there are 80+ operators that can be used within the aggregation pipeline.

Aggregation Pipeline

web: count.ly twitter: @gocountly 4

Countly

web: count.ly twitter: @gocountly 5

• Countly is an analytics and marketing platform for mobile and web.

• Countly processes more than 50 billion data points monthly.• Countly relies heavily on MongoDB and aggregation framework

for data processing and reporting.

Aggregation in Countly

web: count.ly twitter: @gocountly 6

Countly SDK sends data over to Countly Server. Server stores this information in MongoDB individually for each data point. Aggregation framework is used to produce reports for selected view, date and applied filters.

Countly SDK

Aggregation

Example 1: Daily user sessions

web: count.ly twitter: @gocountly 7

Below example data set lists 6 sessions from users a, b, c and d.

ts: timestampdid: device idup: user properties

Example 1: Daily user sessions

web: count.ly twitter: @gocountly 8

Querying number of users and sessions per each day:

Result:

Example 1: Daily user sessions

web: count.ly twitter: @gocountly 9

Pipeline steps:

1. Group all dates, add device ids to an array and count each document as a session2. Use $size to get the length of the device id array which gives us unique user count

per day3. Sort results based on date

Example 1: Daily user sessions

web: count.ly twitter: @gocountly 10

Example 2: Breakdown of user devices in China

web: count.ly twitter: @gocountly 11

Below example data set lists 6 sessions from users a, b, c and d. (Same dataset as Example 1)

ts: timestampdid: device idup: user properties

Example 2: Breakdown of user devices in China

web: count.ly twitter: @gocountly 12

Querying number of users and sessions per each unique device for users from China:

Result:

Example 2: Breakdown of user devices in China

web: count.ly twitter: @gocountly 13

Pipeline steps:

1. Use $match operator to filter all sessions from China2. Group all devices, add device ids to an array and count each document as a session3. Use $size to get the length of the device id array which gives us unique user count

per device

Example 2: Breakdown of user devices in China

web: count.ly twitter: @gocountly 14

Questions?https://count.ly

15