Bird
0
0

You want to add a virtual property fullName combining firstName and lastName in a NestJS schema. How should you do it?

hard📝 Application Q9 of 15
NestJS - Database with Prisma
You want to add a virtual property fullName combining firstName and lastName in a NestJS schema. How should you do it?
ANestJS schemas do not support virtual properties
BAdd <code>@Prop()</code> decorated property <code>fullName</code> and set it manually
CUse schema options with <code>virtuals</code> and define a getter function
DDefine <code>fullName</code> as a method inside the schema class
Step-by-Step Solution
Solution:
  1. Step 1: Understand virtual properties in Mongoose

    Virtuals are properties not stored in DB but computed dynamically using getter functions.
  2. Step 2: Implement virtuals in NestJS schema

    Use schema options to define virtuals and add a getter combining firstName and lastName.
  3. Final Answer:

    Use schema options with virtuals and define a getter function -> Option C
  4. Quick Check:

    Virtuals need schema getter functions [OK]
Quick Trick: Use schema virtuals with getters for computed fields [OK]
Common Mistakes:
  • Trying to store virtuals as real properties
  • Defining virtuals as normal methods
  • Assuming virtuals are unsupported

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes