I want to create a Schema.statics.random function that gets me a random element from the collection. I know there is an example for the native MongoDB driver, b
If you are not wanting to add "test like" code into your schema, this uses Mongoose queries.
Model.count().exec(function(err, count){
var random = Math.floor(Math.random() * count);
Model.findOne().skip(random).exec(
function (err, result) {
// result is random
});
});