Create MongoDB models using Typegoose following project conventions. Use when defining database schemas, creating new models, working with embedded documents, adding indexes for query optimization, or exporting type-safe model instances.
Modular guides for creating type-safe MongoDB models with Typegoose and Mongoose, following project conventions.
Models live in apps/server/src/db/models and use Typegoose to wrap Mongoose. Always use class-based schemas with @modelOptions and the standard @prop decorator from Typegoose.
Note: This project uses SWC for TypeScript compilation with emitDecoratorMetadata enabled, so Typegoose can automatically infer types from TypeScript annotations without explicit type declarations.
| Guide | Use When |
|---|---|
| Property Decorators | Understanding @prop options and patterns |
| Embedded Documents |
| Creating nested objects and arrays of documents |
| Indexes | Optimizing queries with single and compound indexes |
| Common Patterns | Enums, timestamps, references, optional fields, collections |
| Best Practices | Architecture patterns, keeping models pure, sharing schemas |
Beginner: Start with Prop Decorators → Common Patterns → Basic model creation
Intermediate: Add Embedded Documents → Indexes for query optimization
Advanced: Best Practices → Architecture patterns