15
1 MongoDB Aggregation in Countly

MongoDB Aggregation Framework inside Countly

  • Upload
    countly

  • View
    200

  • Download
    1

Embed Size (px)

Citation preview

Page 1: MongoDB Aggregation Framework inside Countly

1

MongoDB Aggregation in Countly

Page 2: MongoDB Aggregation Framework inside 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

Page 3: MongoDB Aggregation Framework inside 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.

Page 4: MongoDB Aggregation Framework inside Countly

Aggregation Pipeline

web: count.ly twitter: @gocountly 4

Page 5: MongoDB Aggregation Framework inside Countly

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.

Page 6: MongoDB Aggregation Framework inside Countly

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

Page 7: MongoDB Aggregation Framework inside Countly

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

Page 8: MongoDB Aggregation Framework inside Countly

Example 1: Daily user sessions

web: count.ly twitter: @gocountly 8

Querying number of users and sessions per each day:

Result:

Page 9: MongoDB Aggregation Framework inside Countly

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

Page 10: MongoDB Aggregation Framework inside Countly

Example 1: Daily user sessions

web: count.ly twitter: @gocountly 10

Page 11: MongoDB Aggregation Framework inside Countly

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

Page 12: MongoDB Aggregation Framework inside Countly

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:

Page 13: MongoDB Aggregation Framework inside Countly

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

Page 14: MongoDB Aggregation Framework inside Countly

Example 2: Breakdown of user devices in China

web: count.ly twitter: @gocountly 14

Page 15: MongoDB Aggregation Framework inside Countly

Questions?https://count.ly

15