Skip to main content

deleteModel*

deleteModel

Typings:

function deleteModel(name: string)

Parameters:

NameTypeDescription
name RequiredstringThe Key to remove from the Cache

deleteModel deletes the given Key (name) from mongoose and the Typegoose Cache, the key is the generated Model Name.

Use deleteModelWithClass when wanting to delete by class instead of by key directly.

caution

This function also deletes the Model from Mongoose itself.

caution

Currently this function does not delete any entries that have different name generation applied at insertion time (like having name generation overwritten in getModelForClass).

caution

Will throw a Error when caching is disabled E033.

class SomeUser {}

const SomeUserModel = getModelForClass(SomeUser);
deleteModel('SomeUser');

deleteModelWithClass

Typings:

function deleteModelWithClass<U extends AnyParamConstructor<any>>(cl: U)

Parameters:

NameTypeDescription
cl RequiredUThe Class to remove from the Cache

deleteModelWithClass tries to find the given Class (cl) in the cache and calls deleteModel with the key the Class has given.

caution

Will throw a Error when caching is disabled E033.

class SomeUser {}

const SomeUserModel = getModelForClass(SomeUser);
deleteModelWithClass(SomeUser);