Skip to main content

buildSchema

Typings:

function buildSchema<U extends AnyParamConstructor<any>>(cl: U, options?: mongoose.SchemaOptions, overwriteOptions?: IModelOptions): mongoose.Schema<DocumentType<InstanceType<U>>>

Parameters:

NameTypeDescription
cl RequiredUThe Class to build a Schema from
optionsIModelOptionsOverwrite Options, like for naming or general SchemaOptions the class gets compiled with

buildSchema compiles the input class cl to a mongoose schema with all options applied.

A compiled model can be re-added with addModelToTypegoose.

tip

For a full example with buildSchema and addModelToTypegoose see Manual Schema Modification.

Example

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

const kittenSchema = buildSchema(Kitten);