AvalonMonoScripts/biggestDownVote7d.js

39 lines
647 B
JavaScript
Raw Normal View History

2021-09-08 11:14:22 +00:00
mongo = require("./mongoHelp.js")
agg = [
{
'$sort': {
'ts': -1
}
}, {
'$unwind': {
'path': '$votes',
'includeArrayIndex': 'string',
'preserveNullAndEmptyArrays': false
}
}, {
'$sort': {
'votes.vt': 1
}
}, {
'$match': {
'votes.claimed': null
}
}, {
'$match': {
'ts': {
'$gt': Date.now()-604800000
}
}
},
{
'$limit': 10
}
]
mongo.aggregate('avalon5', 'contents', agg).then(res => {
res.forEach(element => {
element.claims=Math.floor(element.claims/100)
console.log({id: element._id,vote: element.votes})
})
})