481
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill mx-space/core --skill typegoose-patterns- SKILL.md4.7 KB
Overview
This skill documents TypeGoose model patterns used in MX Space projects. It explains model inheritance, field decorators, indexes, references, nested objects, plugins, protected keys, registration, and common query patterns for building MongoDB schemas with TypeScript and NestJS.
How this skill works
The skill inspects and standardizes TypeGoose model definitions and usage patterns. It shows how to declare models, apply decorators for fields/indexes/references, register models in the database layer, and use models in services with pagination, aggregation, and common queries.
When to use it
- When creating new TypeGoose models for MX Space services
- When defining schema fields, indexes, or reference relations
- When implementing pagination or aggregate pagination in services
- When protecting sensitive fields from direct updates
- When adding plugins like pagination or autopopulate to models
Best practices
- Extend shared BaseModel or WriteBaseModel to inherit common fields (id, created, updated, content fields)
- Use @prop decorators for validation: required, default, unique, trim
- Define class-level @index for common queries and text search to improve performance
- Model relationships with Ref and autopopulate for convenient joins; use local/foreign field virtuals for derived fields
- Register models centrally in the database models array to ensure injection works across modules
- Prefer lean() for read queries that return plain objects, and use model.paginate or aggregatePaginate for paging
Example use cases
- Define a Post model extending WriteBaseModel with title, text, images, and a category reference
- Create a Comment-enabled model using a BaseCommentIndexModel to support comment counts and flags
- Add Count subdocument to track read/like metrics with default values and _id disabled
- Apply mongoose-paginate-v2 and mongoose-aggregate-paginate-v2 plugins to enable standard pagination endpoints
- Protect internal fields (e.g., secret) by listing them in protectedKeys to prevent direct updates via API
FAQ
Use @index({ title: 'text', text: 'text' }) at class level to enable text search across fields.
When should I use lean() on queries?
Use lean() for read-only responses to return plain JavaScript objects and reduce overhead when you don't need mongoose documents.