Skip to main content
POST
Add Course Rating

Overview

Allows students to rate a course they have completed. Ratings are stored with the user’s enrollment record and displayed on course detail pages.

Authentication

Requires Clerk authentication. The user must be enrolled in the course.

Request Body

string
required
The MongoDB ObjectId of the course to rate
number
required
Rating value between 1-5 starsMust be an integer: 1, 2, 3, 4, or 5
string
Optional text review/comment about the courseMaximum length: 500 characters

Response

boolean
Indicates whether the rating was saved successfully
string
Confirmation message
object
The updated course rating information

Request Example

Response Example

Error Responses

  • Missing required fields
  • Invalid rating value (not 1-5)
  • Review text exceeds 500 characters
  • User is not enrolled in the course
  • Course does not exist
  • User has not completed the course yet
  • Ratings may be restricted to completed courses only

Implementation Details

Rating Storage

Ratings are stored in the User model’s courseRatings array:

Rating Update Rules

  • Users can update their rating for a course by submitting again
  • The most recent rating replaces any previous rating
  • Average rating is recalculated for the course after each submission

Code Examples

Use Cases

  1. Collect student feedback on course quality
  2. Display ratings on course pages to help prospective students
  3. Calculate average ratings to rank courses
  4. Identify top-rated courses for marketing purposes