Thursday, 13 June 2019

Schema for workout history MongoDb

I am creating an application where there will be posted workouts and users can record scores to these workouts.​In the future, these workouts may be repeated, and I'd like to be able to compare scores for past results.​const workoutSchema = new Schema({name: { type: String, required: true },description: { type: String, required: true },sets: { type: String, required: false },scoring: { type: String, required: false },publishDate: { type: Date, required: false },createDate: { type: Date, default: Date.now },updateDate: { type: Date, default: Date.now },results: [{type: Schema.Types.ObjectId, ref: 'Result'}],resultsCount: { type: Number, default: 0 },publishedBy: { type: Schema.Types.ObjectId, ref: 'User' },});​How do I model something like this? I was thinking of having a cloned [] field in there where I would store a workout if it were re-used again sometime later in the future, but that brings about the issue of then do I need to have another flag for "clonedFrom" (or something like that). It just seems to get messy.​Ideally, I'd like to structure it so I can easily see the original workout, and anytime it is repeated again in the future.Thoughts? Thanks in advance.

Submitted June 13, 2019 at 01:45PM by Anderology

No comments:

Post a Comment