My current project involves creating a system where users can submit images, which are then stored in a database using a Schema. Users can then use a command (via discord/discordjs) to retrieve a random biased/weighted image from MongoDB and have it sent to them for voting or reporting.
That's the concept, here's what I've accomplished so far:
.
Users can successfully submit images through a discord command.
The MongoDB document is structured with the following values:
const imageSchema = new Schema({
imageId: { type: Number, required: true, index: { unique: true } },
imageLocation: reqString,
votes: {type: Number, required: false, default: 0},
verified: {type: Number, required: false, default: 0},})
Check out an image of how it appears in mongodb compass for additional context
I'm currently stuck on figuring out how to scan all the documents and develop a method to randomly select one of the most highly voted images (not necessarily the highest voted, but ones with more votes should appear more frequently), using JavaScript.
Any suggestions or code snippets illustrating concepts would be greatly appreciated.