Skip to main content

getModelForClass

Typings:

function getModelForClass<U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject>(cl: U, options?: IModelOptions)

Parameters:

NameTypeDescription
cl RequiredUThe Class to build a Model from
optionsIModelOptionsOverwrite some Model options, only property schemaOptions is merged with the existing options

getModelForClass compiled a given Class (cl) into a mongoose.Model, this function will return the existing model if a model of the same name has already been created and cached with addModelToTypegoose.

All options for options.

Example

class Kitten {
@prop()
public name?: string;
}

const KittenModel = getModelForClass(Kitten);