我有两个mongodb收集员工和部门如下 员工集合:
{
"_id" : ObjectId("58c4a35ac2e604024321788e"),
"id_employee" : 19,
"employee_name" : "Lene Vestergaard Hau",
"employee_address" : "Allerton",
"hours" : 279,
"id_department" : 1,
"projects" : [
285,
453,
499,
804,
956
],
"Children" : [
{
"id_child" : 38,
"child_name" : "Caroline Herschel"
}
]
}
部门收集:
{
"_id" : ObjectId("58c49c48c2e669d6555aa5a7"),
"id_department" : 1,
"department_name" : "dept1",
"projects" : [
{
"id_project" : 285,
"project_name" : "1project 285",
"duration" : "211"
},
{
"id_project" : 453,
"project_name" : "1project453",
"duration" : "214"
},
{
"id_project" : 499,
"project_name" : "1project499",
"duration" : "224"
},
{
"id_project" : 804,
"project_name" : "1project804",
"duration" : "217"
}
{
"id_project" : 956,
"project_name" : "1project956",
"duration" : "217"
}
] 我正在尝试执行查找功能以获取有关的所有详细信息 员工的项目。我正在使用的java代码:
coll.aggregate(Arrays.asList(
Aggregates.match(Filters.eq("id_employee",19)),
Aggregates.unwind("$projects"),
Aggregates.lookup("department", "projects", "projects.id_project", "lookupData")
)).forEach(printBlock);
}
上面的代码将lookupData作为空列表返回。有人可以帮忙吗?