Bird
0
0

What will happen if you call TypeOrmModule.forRoot() twice with different configurations in the same NestJS app?

medium📝 component behavior Q5 of 15
NestJS - Database with TypeORM
What will happen if you call TypeOrmModule.forRoot() twice with different configurations in the same NestJS app?
AAn error is thrown due to multiple root connections
BNestJS merges both configurations automatically
COnly the first configuration is used; the second is ignored
DBoth connections are created and used separately
Step-by-Step Solution
Solution:
  1. Step 1: Understand forRoot() behavior

    forRoot() sets up a global database connection. Calling it twice causes conflict.

  2. Step 2: Identify NestJS reaction

    NestJS throws an error because multiple root connections are not allowed by default.

  3. Final Answer:

    An error is thrown due to multiple root connections -> Option A
  4. Quick Check:

    Multiple forRoot() calls = error [OK]
Quick Trick: Only one forRoot() call allowed; duplicates cause error [OK]
Common Mistakes:
  • Thinking configurations merge automatically
  • Assuming multiple connections are created silently
  • Ignoring error thrown on duplicate forRoot()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes