Validate ObjectId Middleware
The Validate ObjectId Middleware ensures that route parameters intended to be MongoDB ObjectIds are valid before the request reaches your controller. This prevents CastError exceptions from Mongoose and ensures strictly typed ID handling.
Installation Guide
Install the component using the servercn CLI:
npx servercn-cli add validate-objectidBasic Implementation
Usage Example
Apply the middleware to any route that contains an :id parameter.