How to define Mongoose schemas
@Schema()
decorator. The @Schema()
decorator accepts an optional configuration object. The configuration object can be used to define the schema’s timestamps.
Use the system schema for internal fields. For example, system.createdAt
and system.modifiedAt
.
_id
field for each document. This field is of type ObjectId
. If you want to disable this behavior for example if this is not a root document, you can set the _id
field to false
.
@Prop()
decorator. The decorator accepts an optional configuration object. The configuration object can be used to define the schema property’s type, default value, and other options.
mongoose
package. This is useful for defining the type of a Mongoose model and working with the schema in other parts of the application.