mongodb通过少量计数随机获得

时间:2016-09-02 07:55:59

标签: node.js mongodb mongoose

我正在计算用户,并找到一个随机的:

 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);
        });

    });
}

在此示例中输出:

  getting the random player
calculating random 
players: 2
random is 2
FINAL RESULT: null
got the result! to show!

在调试中它说它存在2个文件,随机是2个,但它返回零。即使在少量文档上,如何使随机性工作?我做错了什么?

0 个答案:

没有答案