Questions
1 of 25
1How do you define a TypeORM entity and register it in a NestJS feature module?
2How do you handle TypeORM migrations in a NestJS project?
3How do you run a transaction with Prisma in NestJS?
4How do you perform CRUD operations and add query methods to a Mongoose model in NestJS?
5How do you use Prisma with multiple databases in a single NestJS application?
6What is the difference between find(), findOne(), findOneOrFail(), and the Query Builder in TypeORM?
7What are the two main ways to run a database transaction in TypeORM with NestJS?
8How do you handle Prisma migrations in a CI/CD pipeline?
9How do you add schema middleware (hooks) and instance methods in NestJS Mongoose?
10How do you mock a repository in a NestJS unit test?
11How do you seed a database in a NestJS application?
12How do you implement a Unit of Work pattern to group database operations across repositories in NestJS?
13How do you implement optimistic locking with TypeORM to prevent lost updates in NestJS?
14How do you integrate Prisma into a NestJS application?
15How do you implement soft deletes in NestJS with TypeORM?
16How do you implement multi-tenancy with a shared database in NestJS TypeORM?
17How do you set up TypeORM in a NestJS application?
18How do you implement a custom TypeORM repository in NestJS?
19How do you propagate a TypeORM transaction across multiple services in NestJS?
20What are Prisma middleware and how do you use them for audit logging in NestJS?
21How do you set up Mongoose in a NestJS application and define a schema?
22How do you handle Mongoose transactions for multi-document atomic operations in NestJS?
23What is the repository pattern and why use it in NestJS?
24How do you handle database connection pooling and health checks in NestJS?
25How do you implement database read replicas in NestJS for read/write splitting with TypeORM?
01 / 25

How do you define a TypeORM entity and register it in a NestJS feature module?

Difficulty: 5/10
Entity definition, Module registration, Dependency injection

Decorate the class with @Entity() and annotate columns with @Column(), @PrimaryGeneratedColumn(), @CreateDateColumn(), etc. Register the entity in a feature module using TypeOrmModule.forFeature([Entity]) which makes Repository<Entity> available for injection via @InjectRepository().

Entity definition and feature module registration
Entity and module registration rules:
  1. 1

    TypeOrmModule.forFeature([User]) registers Repository<User> in the module's DI scope.

  2. 2

    @InjectRepository(User) is the token used to inject the repository — matches forFeature() registration.

  3. 3

    select: false on @Column() excludes the field from SELECT queries unless explicitly selected.

  4. 4

    Entities must be referenced in TypeOrmModule.forRoot() entities array or glob — otherwise they are invisible.

  5. 5

    @OneToMany, @ManyToOne, @ManyToMany define relationships; always provide the inverse side.

Scenario Questions

0-2 years experience

  1. 1You need to add a new User table to an existing NestJS microservice. Walk me through how you'd create the TypeORM entity class and make sure NestJS knows about it in the UsersModule.
  2. 2If you forget to add the entity to the module's TypeOrmModule.forFeature([...]) array, what runtime error would you see when trying to inject the repository?

2-5 years experience

  1. 1We have a feature module that imports several entities, but after a recent refactor the Order repository injection is failing. How would you debug the issue and what could cause it?
  2. 2Suppose you need to conditionally register an entity only in a development environment. How would you modify the module registration to achieve that, and what trade‑offs does it introduce?

5-8 years experience

  1. 1Our service is scaling to handle thousands of concurrent requests, and we notice many connections being opened to the database. How would you design the entity registration and module imports to minimize connection overhead?
  2. 2We are moving from a monolithic NestJS app to a microservice architecture, and each service needs its own subset of entities. How would you structure the shared TypeORM configuration and module imports to avoid circular dependencies and keep the codebase maintainable?

8+ years experience

  1. 1The company plans to migrate from a single PostgreSQL instance to a sharded multi‑tenant database. How would you redesign the way entities are defined and registered in NestJS modules to support dynamic data source selection per tenant?
  2. 2Legacy code has entities scattered across many feature modules, making migrations painful. What strategy would you propose for consolidating entity definitions and module registrations while minimizing impact on existing teams?

Follow-up Questions

  • What decorator marks a class as a TypeORM entity?
  • How does NestJS resolve the repository instance for an entity?
  • What are the implications of using forFeature in multiple modules?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.