{"id":43414,"library":"nestjs-object-id","title":"NestJS ObjectId Validator and Parser","description":"nestjs-object-id (v4.0.4) provides MongoDB ObjectId validation and parsing for NestJS applications, supporting REST APIs, GraphQL, DTOs, and Microservices. It includes pipes (IsObjectIdPipe, ParseObjectIdPipe) and decorators (@IsObjectId, @ParseObjectId) that integrate seamlessly with NestJS's validation pipeline. Requires @nestjs/common ^10 || ^11, class-validator ^0.14.1, class-transformer ^0.5.1, and mongoose ^7 || ^8 || ^9. Maintained with regular updates; the latest version requires @nestjs/common >=10.2.7 for pipes to work correctly.","status":"active","version":"4.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/vlbras/nestjs-object-id","tags":["javascript","nestjs","mongodb","mongoose","objectid","decorator","class-validator","pipe","graphql","typescript"],"install":[{"cmd":"npm install nestjs-object-id","lang":"bash","label":"npm"},{"cmd":"yarn add nestjs-object-id","lang":"bash","label":"yarn"},{"cmd":"pnpm add nestjs-object-id","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core NestJS framework dependency; pipes require @nestjs/common for parameter decorators","package":"@nestjs/common","optional":false},{"reason":"Required for @IsObjectId decorator to work with DTO validation","package":"class-validator","optional":false},{"reason":"Required for @ParseObjectId decorator to transform strings to ObjectId instances","package":"class-transformer","optional":false},{"reason":"Required for Types.ObjectId type and ObjectId validation logic","package":"mongoose","optional":false}],"imports":[{"note":"ESM import. CommonJS require is also supported but not recommended for NestJS projects using TypeScript.","wrong":"const IsObjectIdPipe = require('nestjs-object-id').IsObjectIdPipe;","symbol":"IsObjectIdPipe","correct":"import { IsObjectIdPipe } from 'nestjs-object-id';"},{"note":"Named export from the main package. No subpath exports.","wrong":"import { ParseObjectIdPipe } from 'nestjs-object-id/pipes';","symbol":"ParseObjectIdPipe","correct":"import { ParseObjectIdPipe } from 'nestjs-object-id';"},{"note":"Decorator is exported from the package root. Works with class-validator.","wrong":"import { IsObjectId } from 'nestjs-object-id/decorators';","symbol":"IsObjectId","correct":"import { IsObjectId } from 'nestjs-object-id';"},{"note":"Custom decorator for transforming strings to ObjectId instances.","wrong":"import { ParseObjectId } from 'class-transformer';","symbol":"ParseObjectId","correct":"import { ParseObjectId } from 'nestjs-object-id';"},{"note":"Types.ObjectId is from mongoose, not from this package.","wrong":"import { Types } from 'nestjs-object-id';","symbol":"Types","correct":"import { Types } from 'mongoose';"}],"quickstart":{"code":"import { IsObjectIdPipe, ParseObjectIdPipe } from 'nestjs-object-id';\nimport { Types } from 'mongoose';\n\n@Controller('items')\nexport class ItemsController {\n  // Validate route param as ObjectId\n  @Get(':id')\n  getItem(@Param('id', IsObjectIdPipe) id: string) {\n    return this.itemsService.findById(id);\n  }\n\n  // Directly parse to Types.ObjectId\n  @Get(':id/details')\n  getDetails(@Param('id', ParseObjectIdPipe) id: Types.ObjectId) {\n    return this.itemsService.findById(id.toString());\n  }\n}","lang":"typescript","description":"Shows usage of IsObjectIdPipe and ParseObjectIdPipe for validating and parsing MongoDB ObjectIds in NestJS route parameters."},"warnings":[{"fix":"Update @nestjs/common to version 10.2.7 or higher.","message":"Requires @nestjs/common >=10.2.7 for pipe support.","severity":"breaking","affected_versions":"<4.0.0"},{"fix":"Upgrade mongoose to version 7.x or higher.","message":"Peer dependency mongoose version updated from ^6 to ^7 in v4 - ensure migration.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Import both pipes and decorators from the main package: 'nestjs-object-id'.","message":"Older versions used 'IsObjectIdPipe' from subpath 'nestjs-object-id/pipes' - this is no longer supported.","severity":"deprecated","affected_versions":"<4.0.0"},{"fix":"Ensure your service methods accept or convert Types.ObjectId as needed.","message":"When using ParseObjectIdPipe, the transformed parameter is of type Types.ObjectId, not string.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Place @IsObjectId() after other class-validator decorators like @IsString() to avoid validation order issues.","message":"The @IsObjectId decorator from this package overrides class-validator's custom validation - ensure it's listed after other decorators.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'0.14.1':51 '0.5.1':55 '10':46 '10.2.7':70 '11':47 '7':58 '8':59 '9':60 'api':22 'applic':19 'class':49,53,83 'class-transform':52 'class-valid':48,82 'correct':75 'decor':33,81 'dtos':24 'graphql':23,86 'id':9 'includ':28 'integr':37 'isobjectid':34 'isobjectidpip':30 'javascript':76 'latest':66 'maintain':61 'microservic':26 'mongodb':12,78 'mongoos':57,79 'nestj':1,7,18,40,77 'nestjs-object-id':6 'nestjs/common':45,69 'object':8 'objectid':2,13,80 'pars':16 'parseobjectid':35 'parseobjectidpip':31 'parser':5 'pipe':29,72,85 'pipelin':43 'provid':11 'regular':63 'requir':44,68 'rest':21 'seamless':38 'support':20 'transform':54 'typescript':87 'updat':64 'v4.0.4':10 'valid':3,14,42,50,84 'version':67 'work':74","created_at":"2026-06-05T16:59:41.035502+00:00","updated_at":"2026-06-05T16:59:41.035502+00:00","problems":[{"fix":"Import from the package root: import { IsObjectIdPipe } from 'nestjs-object-id';","cause":"Importing from a subpath that doesn't exist in the package.","error":"Cannot find module 'nestjs-object-id/pipes' or its corresponding type declarations."},{"fix":"Ensure the route parameter is a 24-character hex string or a valid ObjectId string.","cause":"Pipe validation failed for a route parameter that is not a valid MongoDB ObjectId.","error":"UnhandledPromiseRejectionWarning: BadRequestException: Invalid ObjectId"},{"fix":"Change the parameter type to Types.ObjectId or use IsObjectIdPipe to keep it as string.","cause":"Using ParseObjectIdPipe but the parameter type is declared as string instead of Types.ObjectId.","error":"Type 'string' is not assignable to type 'ObjectId'."},{"fix":"Ensure the value is a string representation of an ObjectId (24 hex characters).","cause":"The @IsObjectId decorator is rejecting a valid ObjectId due to incorrect format (e.g., missing quotes in DTO).","error":"Validation failed (expected type is ObjectId)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/vlbras/nestjs-object-id#readme","github":"https://github.com/vlbras/nestjs-object-id","docs":null,"changelog":null,"pypi":null,"npm":"nestjs-object-id","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}