'Spring boot with MongoDb queries

i have 3 Collections:

Student { Long id, String password, String firstName, String lastName, String email }

Course { Int course_id, Int year, String courseName, Date startDate, Date endDate }

StudentCourse{ Int student_id, Int course_id, Int grade, Date registrationDate }

I want all the optional courses that a student X can add. I try to preform the next query in spring boot:

Select * from course where Today < course.startDate and course.course_id not in (select StudentCourse.course_id from StudentCourse where StudentCourse.student_id=X.id)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source