I have two entities: Course
and User
. Each course can have many users attending it. At the same time, each user can participate in many courses. Each user can give a rating to each course. Each course also has a completion rate (the percentage of users who finished the course with the minimum passing requirements).
I want to query two lists: a class list and a user list. I want the list to be sortable when queried too. The expected sorting behavior is the following.
Course
: sort by highest to lowest and/or lowest to highest ratings, completion rates, and number of users attending itUser
: sort by highest to lowest and/or lowest to highest courses attended and completion rates
What I have thought of is creating two separate collections with the following relevant fields for the two lists.
course
: each course should have a rating field, a completion rate field, and a number of users attending field. These fields will be updated whenever there are triggers that update the rating, completion rate, and number of attendance of the course.user
: each user should have a completion rate field and the number of courses attended field. Similar to thecourse
collection, the fields will be updated on some triggers.
The ratings will reside in a different collection. About the user progress etc, there will be other subcollections/collections to store the details.
I would like to know if there is a better way to model the data such that I can only use one collection to do the above fetching of the lists with the expected sorting behavior.