What is the best way to retrieve random records from MongoDB?
I have come across various articles on StackOverflow discussing this topic, but I am struggling to grasp the concept. For instance:
db.yourCollection.find().limit(-1).skip(yourRandomNumber).next()
How can I implement this code in my own project? (assuming the collection is named User
)
User.findOne(RANDOM PLAYER).then(result) {
console.log(result);
}