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?
CodePudding user response:
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.