0

I am trying to model a database for a fitness app. Currently the 4 main entities are as follows:

Exercise User Workout UserWorkout
id id id id
name email name userId (fk)
body_part name description workoutId (fk)
category password level date
age exerciseIds (fk) time_taken

The app will have default workouts as well as default exercises.


I would like the user to be able to add their own custom workouts/exercises that only they can see (in addition to the default ones) but I'm not sure on how to best structure the data?


1 Answer 1

1

Kris, MongoDB is a schemaless database, what makes it really flexible when it comes down to data modelling. There are different ways of achieving what you described, the one I would recommend would be adding nested documents to the user document if they belong to it. You would have something like this:

User {
  firstName: ...,
  lastName: ...,
  age: ...,
  weight: ...,
  exercises: [
     // User's exercise objects
  ],
  workout: [
     // User's workout objects
  ],
}

This way you can easily have access to information related to the user and avoid using expensive operations like $lookup or querying the database multiple times.

To handle the default exercises/workouts you can have a property in the respective objects like isDefault: true.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Rafael, thanks for your response. One reason why I did not embed the documents was that I would have to repeat the default exercises/workouts for each user. That is a lot of the same data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.