Saturday, 10 November 2018

Mongoose schema and achievement system

Hi,I recently started learning node.js and mongoose and I don't know what is the best way of designing a schema for my project.This is my main schema:let statSchema = new mongoose.Schema({ title: String, linkId: { type: String, unique: true}, stats: { likeCount: { type: Number, default: 0 }, commentCount: { type: Number, default: 0 } } }); Every hour the system checks stats for all linkIds and updates likeCount and commentCount.I want to add an achievement system so that when likeCount updates the system checks if likeCount meets the likeRequirement and if true awards it to corresponding linkId.I was thinking about schema like:let milestonesSchema = new mongoose.Schema({ typeOfAchievement: String, likeRequirement: Number, }); that holds: typeOfAchievement: 100 likes, likeRequirement: 100; typeOfAchievement: 250 likes, likeRequirement: 250 etc.However I don't know how to make it work - should I addmilestones: [{ typeAchieved: String, dateAchieved: Date }] to statSchema or have a third schema that would hold the all achievements for linkIds?let achievementSchema = new mongoose.Schema({ linkId: String, achievementId: String, Date: Date }); Second question is how to perform the check to find out if and what achievement needs to be awarded (so it also doesn't chceck already achieved ones)?

Submitted November 10, 2018 at 06:42PM by BagerCast

No comments:

Post a Comment