I'm trying to make a query to my teams app that do this:
- Create a function that repeats in a certain time - DONE
var now = new Date()
var timeToEndOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999) - now;
if (timeToEndOfDay < 0) {
timeToEndOfDay += 86400000;
}
setTimeout(async function(){
// the mongo query will be here
}, timeToEndOfDay);
Get the user with the most votes for each team (the team is the value of the user_team_nickname_at field) - Half Done
Assign points to each of those users - NOT DONE
Note 1: if the user wins 2 times (the user can do a post with a team and then change a team and post, the points will be assigned to the post that had the most votes, therefore the next user in votes will win
Note 2 the user_team_nickname_at right now has 100 'teams' but this count is dynamic, eventually will have more 'teams'
Mongodb query
const posts = await Posts.find()
.select('user_team_nickname_at vote_up userid')
.sort({vote_up:-1})
.where({'user_team_nickname_at':'team One'})
.limit(1)
res.json({serverResponse:posts})
I need to find a way to iterate between where({'user_team_nickname_at':'dynamicVariable'}) to obtain the first winners of every user_team_nickname_at with the condition specified in Note 1