MongoDb数据库的Employee,Department和Subject课程很少,关系就像这样
public class Employee {
@Id
private long id;
private String name;
@DBRef
private Subject subject;
}
public class subject{
@Id
private long id;
private String name;
@DBRef
private Department department;
}
public class Department{
@Id
private long id;
private String name;
}
我可以使用主题ID
查询员工db.employee.find("subject.$id":<subjectId>)
现在我正在尝试使用departmentId获取部门下的员工但是没有得到任何结果
db.employee.find("subject.department.$id":<departmentId>)
请告诉我使用MongoDB中的departmentId查询员工的任何选项
MongoDB中的示例对象
Employee ::
{"_id": 1,"name":"student1","subject":{"$ref":"subject","$id":1}}
{"_id": 2,"name":"student2","subject":{"$ref":"subject","$id":2}}
{"_id": 3,"name":"student3","subject":{"$ref":"subject","$id":3}}
Subject ::
{"_id": 1,"name":"subject1","department":{"$ref":"department","$id":1}}
{"_id": 2,"name":"subject2","department":{"$ref":"department","$id":1}}
{"_id": 3,"name":"subject3","department":{"$ref":"department","$id":2}}
Department ::
{"_id": 1,"name":"department1"}
{"_id": 2,"name":"department2"}
提前致谢