mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-27 16:06:39 +00:00
added a script to aggregate settings of logged-in users from MongoDB
Change-Id: Id60482999f4baef63da6d76ec4c1604d3c5da921
This commit is contained in:
Executable
+38
@@ -0,0 +1,38 @@
|
||||
allDatabases = db.adminCommand({ "listDatabases": 1 }).databases
|
||||
|
||||
collection = 'PREFERENCES'
|
||||
|
||||
acc = {}
|
||||
|
||||
allDatabases.forEach(function(d) {
|
||||
//database = connect('localhost:27017/' + d.name)
|
||||
database = db.getSiblingDB(d.name)
|
||||
collections = database.getCollectionNames()
|
||||
if (collections.indexOf(collection) >= 0) {
|
||||
usage = database.getCollection(collection).aggregate([{$unwind: "$KEYS_AND_VALUES"}, {$group: {_id:"$KEYS_AND_VALUES.VALUE", total:{$sum:1}}}])
|
||||
|
||||
usage.forEach(function(u) {
|
||||
if (u._id[0] == '{') {
|
||||
if (u._id in acc) {
|
||||
acc[u._id] += u.total
|
||||
} else {
|
||||
acc[u._id] = u.total
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
result = []
|
||||
for (var key in acc) {
|
||||
if (acc.hasOwnProperty(key)) {
|
||||
result.push({"setting": key, "count": acc[key]})
|
||||
}
|
||||
}
|
||||
|
||||
result.sort(function(a, b) { return b.count - a.count })
|
||||
|
||||
for (var i in result) {
|
||||
print("Setting: " + result[i].setting + "\nCount: " + result[i].count + "\n")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user