-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongodb_query
119 lines (105 loc) · 2.36 KB
/
mongodb_query
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//Current Unique users across all streams per state
db.users.aggregate([
{
"$match": {
"timestamp": {"$gte": new Date().getTime()/1000 - 60 * 5}
}
},
{ "$group": {
"_id": {
"geo": "$geo",
"clientID": "$clientid"
},
"count": { "$sum": 1 }
}},
{ "$group": {
"_id": {
"geo": "$_id.geo"
},
"viewerCount": { "$sum": 1 }
}}
])
//Current Unique users across all streams per device type.
db.users.aggregate([
{
"$match": {
"timestamp": {"$gte": new Date().getTime()/1000 - 60 * 5}
}
},
{ "$group": {
"_id": {
"device": "$device",
"clientid": "$clientid"
},
"count": { "$sum": 1 }
}},
{ "$group": {
"_id": {
"device": "$_id.device"
},
"viewerCount": { "$sum": 1 }
}}
])
//Current Unique Users streaming content on
db.users.aggregate([
{
"$match": {"content": "ESPN", "timestamp": {"$gte": new Date().getTime()/1000 - 60 * 5}}
},
{
"$group": {
"_id": {
"content": "$content",
"clientid": "$clientid"
},
"count": { "$sum": 1 }
}
},
{ "$group": {
"_id": {
"content": "$_id.content"
},
"viewerCount": { "$sum": 1 }
}},
{ "$project": { "_id": 0 } }
])
//Current stream count per user
db.users.aggregate([
{
"$match" : {"clientid": "user3", "timestamp": {"$gte": new Date().getTime()/1000 - 60 * 5}}
},
{
"$group": {
"_id": {
"content": "$content",
"clientid": "$clientid"
},
"count": { "$sum": 1 }
}
},
{ "$group": {
"_id": {
"clientid": "$_id.clientid"
},
"streamCount": { "$sum": 1 }
}},
{ "$project": { "_id": 0 } }
])
//Current Unique users across all streams.
db.users.aggregate([
{
"$match": {
"timestamp": {"$gte": new Date().getTime()/1000 - 60 * 5}
}
},
{
"$group":{
"_id": {
"clientid": "$clientid"
}
}
},
{ "$group": {
"_id": null,
"viewerCount": { "$sum": 1 } } },
{ "$project": { "_id": 0 } }
])