added a script to aggregate settings of logged-in users from MongoDB

Change-Id: Id60482999f4baef63da6d76ec4c1604d3c5da921
This commit is contained in:
Axel Uhl
2018-07-16 10:47:00 +02:00
parent 1a9434cf76
commit 7d98cdbea3
+38
View File
@@ -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")
}