I'm using SpringRepository to query mongo db. I have a students
collection with documents like the following.
{
"_id" : ObjectId("52f2139ee4b0384b7402c520"),
"subjects": [
{
"subjectId" : "s001",
"subjectName" : "maths"
},
{
"subjectId" : "s002",
"subjectName" : "science"
},
]
}
I'm going to query this collection using Spring Repository for a subject. I can get a student list with a particular subject like this
@Query("{ 'subjects.subjectName' : ?0 }")
List<Student> findBySubjectName(String subjectName);
But if I want subject only, how to return the a Subject object matching the subject name?