You can create additional collection called Listened Exercises and the fields are
- Name, this is default, can be used as concatenated of logged in user>full name (or email), current exercise.trainer>full name and current exercise.sports>name
- Listening user, relationship to users, multiple listened exercises to 1 user
- Listened Exercise, relationship to Exercises, multiple listened exercises to 1 exercise
- (optional) Trainer, relationship to trainers, multiple listened exercises to 1 trainer (as a shortcut and duplication)
- (optional) Sports, relationship to sports, multiple listened exercises to 1 sport (as a shortcut and duplication)
1 basic field, 4 relationship fields
At Exercises collection, you can add numbers field called counter, this is where we add +1
At Trainer collection, you can add numbers field called counter, this is where we add +1 (same logic)
At Sports collection, you can add numbers field called counter, this is where we add +1 (same logic)
Now for the logic on screen,
Whenever user play the audio session, add action to create this new collection, Listened Exercises and fill the relevant information with current available data.
Add another action to update +1 at Exercises collection, with syntax current exercises>counter+1 (this will hold life time value of this exercise is played by users)
Add another action to update +1 at Trainer collection, with syntax current exercises.trainer>counter+1 (this will hold life time value of all exercises by this trainer is played by users)
Add another action to update +1 at Sports collection, with syntax current exercises.sports>counter+1 (this will hold life time value of all exercises by this sport is played by users)
So, when we want to know which exercises are most listened, we can use count for this new collection, or as backup field, we have counter in the exercise collection that hold life time value of how many user visit this exercise, but if we want to go deeper who are the users, we should use count in the listened exercise collection.
The same logic goes for trainers and sports, they have their own life time value that can work as subtotal of the new collection.