I'm not able to get data from mongodb. When i run server it is showing error like this :
node:15171) UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value "${this.groupId}" at path "_id" for model "Group"
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'
});
}
};