I found mongoose-random package to get a JSON array of random records using mongoose.
I want to get three random records with a specific field. I read the documentation, but I still didn't find any solution. The following code doesn't work.
app.get('/get/random/song/:language/:gender', function (req, res) {
var fields = {lang: req.params.language, gender: req.params.gender};
var filter = {}
var options = {skip: 3, limit: 3};
Song.findRandom(filter, fields, options, function (err, songs) {
res.json(songs);
});
});