spring data – Mongodb – findBy Method for nested objects
Just use the @Query annotation on that method. public interface CustomRepository extends MongoRepository<PracticeQuestion, String> { @Query(value = “{ ‘userId’ : ?0, ‘questions.questionID’ : ?1 }”, fields = “{ ‘questions.questionID’ : 1 }”) List<PracticeQuestion> findByUserIdAndQuestionsQuestionID(int userId, int questionID); } By adding the fields part of the @Query annotation, you are telling Mongo to only return that … Read more