Selecting a random record from Sequelize findAll
You can try this :
Encounter.findAll({ order: Sequelize.literal('rand()'), limit: 5 }).then((encounters) => {
// single random encounter
});
Don't forget to require the Sequelize ð
I think this solution is the most clear one. You should use a random function from a sequelize instance
const sequelize = new Sequelize(url, opts);
Recommend to use a sequelize-cli to generate initial schema, it automatically exports sequelize variable.
Encounter.findOne({
order: sequelize.random()
});
Also with this approach u don't need to solve RAND()
vs RANDOM()
problem if you change a db dialect from postgres to MySQL or back.