Skip to main content

Default Classes

This Guide contains all default classes Typegoose provides.

note

All properties provided are just types to show which are available from Mongoose, or stated otherwise.

TimeStamps​

The TimeStamps class provides the following fields:

Field NameType
createdAtDate
updatedAtDate

And also applies the following schemaOptions:

Field NameValue
timestampstrue

Base​

The Base Interface provides the following fields:

Field NameType
_idmongoose.Types.ObjectId
idstring

How to override _id type:

This only works with typegoose 6.0.2+
interface Something extends Base {} // have the interface to add the types of "Base" to the class
class Something {} // have your class, OR
class Something extends TimeStamps {} // have your class extend some other class

FindOrCreate​

This class provides all the types supplied by the plugin mongoose-findorcreate.

note

This class should only be used, if the plugin is used too

An Example can be seen in common-plugins

Extra information​

Use multiple classes together​

Because Typescript & JavaScript don't have functions for multiple inheritance, it can only be achieved by the following

interface Something extends Base {} // have the interface to add the types of "Base" to the class
class Something extends TimeStamps {} // have your class
note

This only works because Base only has types and does not modify anything.