0
Can you help me? I am trying to show my Database records in ascending order, but it is an object within another and I want to organize by cashout follows the photo of my DB.
I am using the Mongoose and expressjs below as I am searching the data:
var Serial = function(){
this.sumTotalBets = function(game){
var totalBet = 0;
game.findOne({gameStatus:'in progress'}, function(err, games){
if(err){throw err}
for(var i = 0; i < games.players.length; i++){
totalBet += Number(games.players[i].bet);
}
totalBet = totalBet.toFixed(8);
console.log('Soma de tudo ' + totalBet);
for(i = 0; i < games.players.length; i++){
var verify = Number(games.players[i].profit);
if(totalBet > verify.toFixed(8)){
totalBet -= verify;
console.log('Continua ' + i + ' ' + totalBet.toFixed(8));
}else{
console.log('Parou em ' + i + ' ' + totalBet.toFixed(8) + ' PayOut ' + (games.players[i].cashOut - 0.01).toFixed(2));
}
}
});
}
}
module.exports = new Serial();
CONSOLE RESULT
Soma de tudo 0.00263300
Continua 0 0.00262765
Continua 1 0.00252380
Parou em 2 0.00252380 PayOut 100.98
Continua 3 0.00252180
Parou em 4 0.00252180 PayOut 1.99`
Summing up I want to list players by where increasing cashout