1// it happens when you pass an invalid id to mongoose.
2// so first check it before proceeding, using mongoose isValid function
3
4import mongoose from "mongoose";
5
6// add this inside your route
7if( !mongoose.Types.ObjectId.isValid(id) ) return false;
8
1import mongoose from "mongoose";
2
3// add this inside your route
4if( !mongoose.Types.ObjectId.isValid(id) ) return false;