Typegoose Modeling
Modular guides for creating type-safe MongoDB models with Typegoose and Mongoose, following project conventions.
Core Concepts
Models live in apps/server/src/db/models and use Typegoose to wrap Mongoose. Always use class-based schemas with @modelOptions and typed property decorators from apps/server/src/db/prop.ts.
CRITICAL: This project uses custom property decorators (objectIdProp, stringProp, etc.) instead of raw @prop decorators. These provide proper type inference automatically. See references/prop-decorators.md for complete details.
Quick Reference
| Guide | Use When |
|---|---|
| Prop Decorators | Understanding available field decorators and type inference |
| 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 |
Learning Path
Beginner: Start with Prop Decorators → Common Patterns → Basic model creation
Intermediate: Add Embedded Documents → Indexes for query optimization
Advanced: Best Practices → Architecture patterns
See Also
- •examples/basic-model.ts - Simple model structure
- •examples/model-with-indexes.ts - Single and compound indexes
- •examples/embedded-documents.ts - Nested documents