【发布时间】:2019-02-17 03:58:37
【问题描述】:
我无法查询特定部门中包含的所有个人资料。
我将 nodejs 与 mongo 和 mongoose 一起使用。下面是一个 Profile 模式的示例:
Profile: {
"level": 1,
"departments": [
{
"_id": "5c5f3bb4338fde6c60a684d4",
"department": "5c106a324acd0571241323f2",
"name": "Calidad"
},
{
"_id": "5c5f3794eca3f14cd49e395e",
"department": "5c106bad99142733446a44f0",
"name": "Mantenimiento"
}
]
以下是我尝试过的查询:
Profile.find({ departments: [{ department: req.params.id }] })
.then(profiles => res.json(profiles))
.catch(err =>
res.status(404).json({ nodepartmentfound: "No departments found" })
);
我希望返回包含指定部门的所有个人资料的 tan 数组。
【问题讨论】: