repo.or.cz
/
gitter.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
history
|
raw
|
HEAD
Fix config formatting
[gitter.git]
/
scripts
/
useful-queries
/
true-room-membership.js
blob
3186d2ce6859c0b02602b70b45d97044d7eeecfa
1
rs.slaveOk();
2
3
var result = db.troupeusers.aggregate([
4
{
5
$group: {
6
_id: '$troupeId',
7
count: { $sum: 1 }
8
}
9
},
10
{
11
$sort: {
12
count: -1
13
}
14
},
15
{
16
$limit: 10
17
},
18
{
19
$lookup: {
20
from: 'troupes',
21
localField: '_id',
22
foreignField: '_id',
23
as: 'troupe'
24
}
25
},
26
{
27
$unwind: '$troupe'
28
},
29
{
30
$project: {
31
_id: 1,
32
uri: '$troupe.uri',
33
count: 1
34
}
35
}
36
]);
37
38
print('Troupe\tCount');
39
result.forEach(function(x) {
40
print(x.uri + '\t' + x.count);
41
});