Bird
0
0

Why is it important to use the @Schema() decorator instead of plain classes when defining schemas in NestJS?

hard📝 Conceptual Q10 of 15
NestJS - Database with Prisma
Why is it important to use the @Schema() decorator instead of plain classes when defining schemas in NestJS?
AIt converts classes to TypeORM entities
BIt automatically creates database indexes
CIt enables NestJS to generate Mongoose schemas with metadata
DIt is only for documentation and has no runtime effect
Step-by-Step Solution
Solution:
  1. Step 1: Role of @Schema() decorator

    The @Schema() decorator adds metadata so NestJS can generate Mongoose schemas from classes.
  2. Step 2: Clarify misconceptions

    It does not create indexes automatically, nor is it related to TypeORM, and it has runtime effect (not just documentation).
  3. Final Answer:

    It enables NestJS to generate Mongoose schemas with metadata -> Option C
  4. Quick Check:

    @Schema() adds metadata for schema generation [OK]
Quick Trick: @Schema() adds metadata for Mongoose schema creation [OK]
Common Mistakes:
  • Thinking @Schema() creates indexes automatically
  • Confusing with TypeORM decorators
  • Assuming it has no runtime effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes