Skip to main content

FAQ

Repository

What happened to the original author?

A: The original author szokodiakos (github name) has abandoned the project, but might look into it again at some time.

Is this Project still active?

A: Yes it is, but not on the main repository anymore because of What happened to the original author? and Github Permissions (TL;DR: a collaborator cannot add another collaborater, only the owner can)

Why is the package now released in another package?

(context: from typegoose to @typegoose/typegoose)
A: Because of a Repository Switch (reasons) and because a name cannot be used by multiple packages, except if it is scoped.

Why @typegoose/typegoose

A: Because I (hasezoey) don't have permissions over the old typegoose repository and I dont want to touch the old npm package. It is a typical forking and continuation of an OSS project.

Functional

Why does new Model({}) not have types?

A: Because Typegoose doesn't modify any Mongoose code, it is still the same as Mongoose's original new Model(), you would have to do new Model({} as Class) (or sometimes new Model({} as Partial<Class>), because of functions.)

Do all Classes get compiled to their own mongoose.Schema?

A: Yes, all classes compiled through typegoose (like type: () => SubClass, or by reflection) will be their own mongoose.Schema.

This means that the following is equal:

// Native Mongoose
const subSchema = new mongoose.Schema({ someprop: { type: String } });
const mainSchema = new mongoose.Schema({
subDoc: subSchema
})

// Typegoose
class Sub {
@prop()
public someprop: string;
}

class Main {
@prop()
public subDoc: Sub; // by reflection, not explicitly defining option "type"
// OR
@prop({ type: () => Sub }) // defining option "type" explicitly
public subDoc: Sub;
}

There is also a option to not use sub-classes, called the Passthrough class

Edge Cases

I want to the return document with property id instead of _id

Mongoose automatically adds a virtual named id, use the following for type definitions:

class Cat {
id: mongoose.Types.ObjectId;
_id: mongoose.Types.ObjectId;
}