Skip to content

Latest commit

 

History

History
66 lines (48 loc) · 3.16 KB

setGlobalOptions.md

File metadata and controls

66 lines (48 loc) · 3.16 KB
id title
set-global-options
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.

:::caution 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 {#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: