0
0
NestJSframework~10 mins

Schema definition in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Schema decorator from Mongoose.

NestJS
import { [1] } from '@nestjs/mongoose';
Drag options to blanks, or click blank then click option'
ASchema
BModule
CController
DInjectable
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Module or Controller instead of Schema
Forgetting to import from '@nestjs/mongoose'
2fill in blank
medium

Complete the code to define a schema class named User.

NestJS
@[1]()
export class User {}
Drag options to blanks, or click blank then click option'
AController
BSchema
CInjectable
DModule
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Injectable or @Controller instead of @Schema
Missing parentheses after the decorator
3fill in blank
hard

Fix the error in the property decorator to define a schema property.

NestJS
import { Prop } from '@nestjs/mongoose';

@Schema()
export class Product {
  @[1]()
  name: string;
}
Drag options to blanks, or click blank then click option'
AProp
BProperty
CSchema
DField
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Property or @Field which are not valid in NestJS Mongoose schemas
Forgetting to import Prop
4fill in blank
hard

Fill both blanks to create a schema factory for the User class.

NestJS
export const UserSchema = [1](User, [2]);
Drag options to blanks, or click blank then click option'
ASchemaFactory.createForClass
BUser
C{ timestamps: true }
DProp
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name instead of the factory method
Passing the class name as second argument instead of options object
5fill in blank
hard

Fill all three blanks to define a schema with a required string property 'title'.

NestJS
@Schema()
export class Book {
  @[1]({ required: [2] })
  [3]: string;
}
Drag options to blanks, or click blank then click option'
AProp
Btrue
Ctitle
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using false instead of true for required
Missing the property name or using wrong decorator