node.js - mongodb get random by low amount of counts -


im counting users, , finding 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 " + rand);          users.findone().skip(rand).then(function(playerresult) {             console.log("final result: " + playerresult);            return resolve(playerresult);         });      }); } 

in example output:

  getting random player calculating random  players: 2 random 2 final result: null got result! show! 

in debug says exist 2 documents, , random two, returns zero. how can make randomness work on low amount of documents? have done wrong ?


Comments