Skip to main content

getClassForDocument

Removed in 10.0

Typings:

function getClassForDocument(document: mongoose.Document): NewableFunction | undefined

Parameters:

NameTypeDescription
document Requiredmongoose.DocumentThe Document to get the Class from

getClassForDocument is used to get a Class from a document (which either has a .typegooseName function or property), this function is a more specific case of getClass.

note

This function only works if the schema has been created with buildSchema or a property / function has been manually added.

caution

This Function has been removed in typegoose 10.0, use getClass instead.

Example‚Äč

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

const KittenModel = getModelForClass(Kitten);

const doc = new KittenModel();

getClassForDocument(doc) === Kitten; // should be "true"