I have a Mongo document which is like this :
db.user.find()
{
"_id" : ObjectId("560fa0c730a8e74bbd69c094"),
"name" : "abc",
"employee" : [{
"_id" : BinData(3,"v0m0V46pok94fVfwGkFVig=="),
"team" : "Dev Engineer",
}]
}
class User
{
String name;
String id;
}
class Employee
{
UUID id;
String team;
}
public interface EmployeeRepository extends MongoRepository<Employee, String>
{
@Query(value = "{ 'employee._id' : ?0 }")
Medication findByEmployeeId(UUID Id);
}
I want to find the employee by id and write a find method using the employee._id. Is there anyway to do this using MongoRepository, or should I return the entire array and loop through it? I tried the above method findByEmployeeId(UUID Id), but it does not work. I am not sure if the @Query annotation is necessary here. Please suggest!