0

I'm using Spring Data MongoDB and, say want to query the following document:

{
  "id":3, 
  "updatedOn" : ISODate("2018-11-22T10:58:48.536Z"),
  "totalMaxScore" : 50,
  "maxAttempts" : 4,
  "sections" : [
      {
       "sectionName" : "coding",
       "maxScore" : 30,
       "concepts" : [
           "css box model"
       ],
       "skills" : [
           "is aware of css syntax"
       ],
       "difficultyLevel" : "easy",
       "weightage" : 48
     }
  ]

From Mongo Client I'm able to do: db.quiz.find({'sections.skills': 'is aware of css syntax'}).pretty()

But I want to search programatically documents based on skills provided at runtime. I understand I need to use @Query but need help on the generic query to write.

user2693135
  • 1,206
  • 5
  • 21
  • 44

1 Answers1

0

Sorry for the late answer.

@Query(value = "{ 'sections':{$elemMatch:{'skills: {$elemMatch: {$eq: ?0 }}}}})"
List<Challenge> findChallengesBySkill(String skill);
charlycou
  • 1,778
  • 13
  • 37