buildSchema
Typings:
function buildSchema<U extends AnyParamConstructor<any>>(cl: U, options?: mongoose.SchemaOptions, overwriteOptions?: IModelOptions): mongoose.Schema<DocumentType<InstanceType<U>>>
Parameters:
Name | Type | Description |
---|---|---|
cl Required | U | The Class to build a Schema from |
options | IModelOptions | Overwrite 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);