Im currently counting users, and finding a random one:
Users.count(function(error,count) {
console.log("calculating random ");
console.log("players: " + count);
var rand = Math.floor(Math.random() * count) + 1;
console.log("random is " + rand);
Users.findOne().skip(rand).then(function(playerresult) {
console.log("FINAL RESULT: " + playerresult);
return resolve(playerresult);
});
});
}
in this example output:
getting the random player
calculating random
players: 2
random is 2
FINAL RESULT: null
got the result! to show!
In the debug it says it exist 2 documents, and random is two, but it returns zero. how can i make the randomness work even on low amount of documents? have i done something wrong ?