- Home
- Skills
- Pluginagentmarketplace
- Custom Plugin Mongodb
- Mongodb Index Creation
mongodb-index-creation_skill
- Python
1
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 pluginagentmarketplace/custom-plugin-mongodb --skill mongodb-index-creation- SKILL.md7.8 KB
Overview
This skill teaches practical MongoDB index creation and types to dramatically improve query performance. It covers single-field, compound, unique, sparse, text, geospatial, and TTL indexes, plus management and monitoring techniques. Learn patterns like ESR (Equality, Sort, Range) and how to design covered queries to avoid document fetches.
How this skill works
The skill explains how to create indexes with concrete examples and options (unique, sparse, background, expireAfterSeconds, collation, custom names). It inspects common query patterns and shows how to select index types and field order to enable index scans, covered queries, or geospatial and full-text searches. It also covers listing, dropping, and monitoring index usage with indexStats.
When to use it
- Optimize queries that filter or sort frequently accessed fields
- Enforce uniqueness on keys like email or username
- Support full-text search across title/content using text indexes
- Store geo-coordinates and run proximity queries with 2dsphere
- Auto-expire sessions, caches, or temporary logs with TTL indexes
- Create covered queries to avoid fetching full documents
Best practices
- Design indexes for actual queries — index what you filter/sort on
- Apply the ESR rule: Equality first, Sort second, Range last in compound indexes
- Avoid over-indexing; every index adds write and storage cost
- Create indexes early and batch-create when initializing large datasets
- Use explain() and $indexStats to verify usage and remove unused indexes
Example use cases
- Unique user sign-up: create unique index on email to prevent duplicates
- Recent orders list: compound index on {status:1, createdAt:-1} for filtered, sorted queries
- Session cleanup: TTL index on createdAt to auto-remove expired sessions
- Local discovery: 2dsphere index for finding nearby venues by lat/long
- Article search: text index across title and content with weighted fields
FAQ
Follow ESR: put equality fields first, fields used for sorting next, and range fields last. Order affects which query shapes the index supports.
When should I use sparse vs unique+sparse?
Use sparse when a field is optional to keep the index small. Combine unique with sparse to allow multiple documents with a missing/null field while enforcing uniqueness for present values.