我无法从mongodb获取数据。当我运行服务器时,它显示如下错误:
node:15171)UnhandledPromiseRejectionWarning:CastError:Cast to 模型的路径“ _id”处的值“ $ {this.groupId}”的对象标识失败 “组”
export const getGroup = async (req, res) => {
const {groupId} = req.params;
if (!groupId) {
return res.status(400).json({
error: true,
message: 'You need to provided a group id'
});
}
// Search for see if group exist
const group = await Group.findById(groupId);
if (!group) {
return res.status(400).json({
error: true,
message: 'Group not exist'
});
}
try {
return res.status(200).json({
error: false,
meetups: await Meetup.find({ group: groupId }).populate('group', 'name')
});
} catch (e) {
return res.status(400).json({
error: true,
message: 'Cannot fetch meetup'
});
}
};