{"id":11387,"library":"nestjs-dynamoose","title":"NestJS Dynamoose Integration","description":"nestjs-dynamoose is a module designed to seamlessly integrate the Dynamoose ODM (Object Document Mapper) for DynamoDB into NestJS applications. It provides NestJS-specific modules and decorators that leverage NestJS's robust dependency injection system, allowing developers to define DynamoDB schemas and models in a structured, modular way. The current stable version is 0.6.0, with releases occurring frequently to maintain compatibility with new versions of NestJS and Dynamoose. Key differentiators include its adherence to NestJS architectural patterns (e.g., `forRoot`, `forFeature`), simplifying the setup and management of DynamoDB connections and models compared to integrating Dynamoose directly without the NestJS wrapper, and enabling easy configuration of AWS credentials and local DynamoDB instances.","status":"active","version":"0.6.0","language":"javascript","source_language":"en","source_url":"https://github.com/hardyscc/nestjs-dynamoose","tags":["javascript","typescript"],"install":[{"cmd":"npm install nestjs-dynamoose","lang":"bash","label":"npm"},{"cmd":"yarn add nestjs-dynamoose","lang":"bash","label":"yarn"},{"cmd":"pnpm add nestjs-dynamoose","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Underlying AWS SDK for DynamoDB operations, required by Dynamoose.","package":"@aws-sdk/client-dynamodb","optional":false},{"reason":"Core NestJS framework peer dependency for common utilities and decorators.","package":"@nestjs/common","optional":false},{"reason":"Core NestJS framework peer dependency for module and application bootstrap.","package":"@nestjs/core","optional":false},{"reason":"The Object Document Mapper (ODM) for DynamoDB that this package wraps.","package":"dynamoose","optional":false},{"reason":"Required by NestJS for TypeScript decorators and metadata reflection.","package":"reflect-metadata","optional":false},{"reason":"Reactive programming library, a standard peer dependency for NestJS.","package":"rxjs","optional":false}],"imports":[{"note":"nestjs-dynamoose is designed for modern NestJS projects primarily using ES Modules.","wrong":"const { DynamooseModule } = require('nestjs-dynamoose');","symbol":"DynamooseModule","correct":"import { DynamooseModule } from 'nestjs-dynamoose';"},{"note":"The Dynamoose Schema class is imported directly from the `dynamoose` package, not the wrapper.","wrong":"import { Schema } from 'nestjs-dynamoose';","symbol":"Schema","correct":"import { Schema } from 'dynamoose';"},{"note":"Type definitions for Dynamoose models are exported by the underlying `dynamoose` library.","wrong":"import { Model } from 'nestjs-dynamoose';","symbol":"Model type","correct":"import { Model } from 'dynamoose';"}],"quickstart":{"code":"import { Module } from '@nestjs/common';\nimport { DynamooseModule } from 'nestjs-dynamoose';\nimport { Schema } from 'dynamoose';\n\n// user/user.schema.ts\nexport const UserSchema = new Schema({\n  id: {\n    type: String,\n    hashKey: true\n  },\n  name: {\n    type: String\n  },\n  email: {\n    type: String\n  }\n});\n\n// user/user.service.ts (simplified)\nimport { Injectable } from '@nestjs/common';\nimport { Model } from 'dynamoose';\nimport { InjectModel } from 'nestjs-dynamoose';\n\ninterface UserKey { id: string; }\ninterface User extends UserKey { name: string; email?: string; }\n\n@Injectable()\nexport class UserService {\n  constructor(@InjectModel('User') private userModel: Model<User, UserKey>) {}\n\n  async create(user: User): Promise<User> {\n    return this.userModel.create(user);\n  }\n}\n\n// user/user.module.ts\n@Module({\n  imports: [\n    DynamooseModule.forFeature([{\n      name: 'User',\n      schema: UserSchema,\n      options: {\n        tableName: 'user-table-name' // Explicit table name\n      }\n    }])\n  ],\n  providers: [UserService],\n  exports: [UserService]\n})\nexport class UserModule {}\n\n// app.module.ts\n@Module({\n  imports: [\n    DynamooseModule.forRoot({\n      aws: {\n        region: process.env.AWS_REGION ?? 'us-east-1',\n        accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? '',\n        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? ''\n      },\n      local: process.env.DYNAMODB_ENDPOINT ?? false // Set to true or 'http://localhost:8000' for local DynamoDB\n    }),\n    UserModule\n  ]\n})\nexport class AppModule {}","lang":"typescript","description":"This quickstart demonstrates how to configure Dynamoose at the root of a NestJS application, define a Dynamoose schema, register it with a feature module, and inject the Dynamoose model into a service for data operations."},"warnings":[{"fix":"Ensure your NestJS monorepo dependencies (`@nestjs/common`, `@nestjs/core`) match the peer dependency range specified for the installed `nestjs-dynamoose` version.","message":"The peer dependency for NestJS has been updated multiple times, requiring users to upgrade their NestJS versions. Specifically, v0.6.0 requires NestJS 11, v0.5.5 required NestJS 10, and older versions required 8 or 9.","severity":"breaking","affected_versions":">=0.5.5"},{"fix":"Refactor your `DynamooseModule.forFeature()` configuration. Instead of `schema: { tableName: 'my-table', ... }`, use `options: { tableName: 'my-table' }` as a sibling to `schema`.","message":"The `tableName` property, previously configurable directly within the schema definition, was moved to the `options` object within `DynamooseModule.forFeature()`.","severity":"breaking","affected_versions":">=0.5.4"},{"fix":"Update all occurrences where you previously referred to 'document' in your code (e.g., interface names, variable names) to 'item'.","message":"The terminology `document` was renamed to `item` to align with Dynamoose v3 conventions and prevent confusion with MongoDB documents.","severity":"breaking","affected_versions":">=0.5.3"},{"fix":"Upgrade your `dynamoose` package to a version compatible with your `nestjs-dynamoose` installation, typically `^3.2.0` or `^4.0.0` depending on the `nestjs-dynamoose` version.","message":"The peer dependency for `dynamoose` has been updated, requiring users to upgrade their `dynamoose` library. Version 0.5.6 introduced support for Dynamoose v4, and v0.5.4 added support for Dynamoose v3.2.0.","severity":"breaking","affected_versions":">=0.5.4"},{"fix":"If defining `forRootAsync` with `useFactory`, ensure your factory function signature includes an ignored first parameter, e.g., `useFactory: async (_, configService: ConfigService) => ({ /* ... */ })`.","message":"When using `DynamooseModule.forRootAsync()`, the `useFactory` callback's first parameter is reserved for future use and should be ignored (e.g., by using `_`).","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `DynamooseModule.forFeature()` is imported in the relevant feature module and that `InjectModel('YourModelName')` is used correctly in the service constructor, matching the name provided in `forFeature`.","cause":"The Dynamoose model was not correctly injected or the feature module was not imported.","error":"Nest can't resolve dependencies of the XService (?, YRepository)"},{"fix":"Add `DynamooseModule.forRoot()` (or `forRootAsync()`) to the `imports` array of your main `AppModule` to initialize the Dynamoose connection.","cause":"The `DynamooseModule.forRoot()` or `DynamooseModule.forRootAsync()` was not called or configured in the root `AppModule`.","error":"No provider for DynamooseModuleOptions! (or similar DI error related to DynamooseModule)"},{"fix":"Check your `package.json` and `package-lock.json` for multiple versions of `dynamoose` or its types. Try `npm dedupe` or manually adjust versions to a single, compatible one.","cause":"Inconsistent versions of `dynamoose` or `@types/dynamoose` in your project dependencies, often caused by transitive dependencies or different peer dependency requirements.","error":"Type 'Schema<any, any>' is not assignable to type 'Schema<any, any>'"},{"fix":"Move `tableName` from the schema definition to the `options` property within the object passed to `DynamooseModule.forFeature()`, ensuring it's a string.","cause":"The `tableName` option is missing or incorrectly specified in `DynamooseModule.forFeature()`'s options, or is still located in the old schema definition after v0.5.4.","error":"Invalid table options: Table name must be a string"}],"ecosystem":"npm"}