Filtering info between 2 datasets using code

I have 2 databases.
Database1 has the Course Name.
Database2 is a student directory of the classes they are enrolled for.
Im trying to create a repeater with a table inside.
Each repeater box, is a course from courseName
I need the table to show which students are registered for each course.

When the students registered, they could have registered up to 14 different classes.
So there are 14 columns that have to be sorted and compared to Course Name

I know I need to use something like this (but this isn’t it)

$w(" #studentDataset ").setFilter(wixData.filter()
.contains(“class1”,( ‘courseName’).value);

class1 is in the student dataset (database2) and matches courseName (database1)

The repeater works, but I can’t get it to filter to who is in the class, it shows all students
thank you for any help possible