home / skills / ehtbanton / claudeskillsrepo / mongodb-schema-generator

mongodb-schema-generator skill

/mongodb-schema-generator

This skill generates complete Mongoose schema files with validation, indexes, and virtuals for TypeScript projects.

npx playbooks add skill ehtbanton/claudeskillsrepo --skill mongodb-schema-generator

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
744 B
---
name: mongodb-schema-generator
description: Generate MongoDB/Mongoose schema files with validation, indexes, and virtuals. Triggers on "create mongodb schema", "generate mongoose model", "mongo schema", "mongoose model for".
---

# MongoDB Schema Generator

Generate Mongoose schema files with validation, indexes, virtuals, and methods.

## Output Requirements

**File Output:** `*.model.ts` or `*.schema.ts`
**Format:** Valid Mongoose TypeScript
**Standards:** Mongoose 8.x with TypeScript

## When Invoked

Immediately generate a complete Mongoose schema with validation and indexes.

## Example Invocations

**Prompt:** "Create MongoDB schema for blog posts"
**Output:** Complete `post.model.ts` with validation, indexes, and virtuals.

Overview

This skill generates ready-to-use Mongoose schema and model files in TypeScript for MongoDB. It produces complete *.model.ts or *.schema.ts files that include validation, indexes, virtuals, static and instance methods, and TypeScript types compatible with Mongoose 8.x. The output is designed for direct use in a Node.js/TypeScript codebase.

How this skill works

When triggered, the skill analyzes the provided entity description, fields, and relationships and emits a fully formed TypeScript Mongoose schema file. It includes field types, required/optional flags, custom validators, compound and single-field indexes, virtual properties, and example statics/methods. The generated file follows Mongoose 8.x TypeScript patterns and compiles-ready structure.

When to use it

  • Creating new collection models quickly from plain language descriptions.
  • Converting an entity spec or ERD into a working Mongoose model.
  • Adding validation rules and indexes during initial schema design.
  • Scaffolding virtuals, populated relationships, and helper methods.
  • Prototyping APIs that require immediate TypeScript model files.

Best practices

  • Provide a field list with types, required flags, default values, and any range/format constraints.
  • Specify relationships (refs) and whether to populate via virtuals or direct ObjectId fields.
  • Describe common queries so indexes can be recommended (e.g., frequent sort or filter fields).
  • Review generated validators and adjust custom logic to match domain rules.
  • Keep model files focused: extract complex business logic to separate service modules.

Example use cases

  • Generate a post.model.ts for a blog with title, body, tags, author ref, publishedAt, and a slug virtual.
  • Create a user.model.ts with email uniqueness index, password hashing hooks, and a fullName virtual.
  • Scaffold an order.model.ts with compound indexes for customerId + createdAt and monetary field validation.
  • Produce comment.model.ts with references to post and author and a method to short-preview content.

FAQ

Which file names and formats does the skill output?

It outputs TypeScript files named with .model.ts or .schema.ts containing a Mongoose schema and model compatible with Mongoose 8.x.

Can it add indexes and virtuals automatically?

Yes — provide indexing needs and computed fields in the prompt and the generator will add single-field and compound indexes as well as virtuals.