var file = fs.createReadStream("somefilethatnotexist.html");
file.on("error", (err) => {
console.log('I got error!');
});
server.on("error", (err) => {
console.log('I got error!');
});
myCollection.aggregate([
{'$project': {
"stat": 1,
"userID": 1,
"statParsed": {"$objectToArray": "$stat"}
}},
{"$unwind": "$statParsed"},
{"$group": {
"_id": {
"userID": "$userID",
"stat": "$stat"
},
"sum": {"$sum": "$statParsed.v"}
}}
]).sort({"sum": -1}).toArray((err, data) => {
...
});