setGlobalOptions
Typings:
function setGlobalOptions(options: IGlobalOptions)
Parameters:
Name | Type | Description |
---|---|---|
options | IGlobalOptions | The Options to apply globally |
setGlobalOptions
is used to set schemaOptions
and options
of IModelOptions
globally (applied to all schemas created by buildSchema
) and also set some global operation options for typegoose with globalOptions
property.
Only the specified options in options
are changed, if a subsequent call is made with different keys, it will not affect other keys, only the first 2 levels are merged.
The setGlobalOptions
call has to be before any buildSchema
(by extension also getModelForClass
) calls, which means when doing export const Model = buildSchema(class)
, the setGlobalOptions
call has to be before any of the imports that export schemas / models.
Example
setGlobalOptions({ options: { allowMixed: Severity.ERROR } });
setGlobalOptions({ globalOptions: { disableGlobalCaching: true } }); // does not affect the previous setting of "options"
setGlobalOptions({ globalOptions: { someOtherOption: true } }); // does not affect the previous setting of "globalOptions"
setGlobalOptions({ options: { disableLowerIndexes: true, allowMixed: Severity.WARN } }); // will overwrite previous setting of "allowMixed"
// the global options would now look like
{
options: {
allowMixed: Severity.WARN,
disableLowerIndexes: true
},
globalOptions: {
disableGlobalCaching: true,
someOtherOption: true
}
}
Global Typegoose Options
disableGlobalCaching
Default: false
Disables Caching Globally (cannot be overwritten by disableCaching
).
Setting this will not clear the existing cache.
If only locally disabled cache is needed, see @modelOptions
's disableCaching
which does not have much of the following effects.
Effects:
deleteModel
&deleteModelWithClass
will throwE033
when usedgetClass
will throwE033
when usedgetModelWithString
will throwE033
when usedbuildSchema
will not add anything to theconstructors
cacheaddModelToTypegoose
will not add anything toconstructors
andmodels
cache (but will still check if the class and model are valid)getModelForClass
&getDiscriminatorModelForClass
will not try to get anything from cache