0

I am using following code to define a mongodb entity.

@Schema({})
export class User extends BaseModel {
    @Prop({ type: [String], required: true })
    subjects: string[]; // line 1
    // subjects: [string]; // line 2
  
}

What is the difference between line 1 and line 2 for defining a mongodb entity property?

1 Answers1

0

According to the Mongoose SchemaTypes Documentation for Arrays, the type definition Type[] and [Type] are interchangeable. You could also use Array<Type>. They are essentially all the same internally.

bajro
  • 1,199
  • 3
  • 20
  • 33