AGENT SKILL

mongodb-pro

MongoDB modeling, aggregation pipelines, and operations — use when designing schemas or tuning Mongo queries.

License 许可
MIT
所属仓库
TanNhatCMS/jarvis
最近更新
2026-11-07
Stars
★ 0
Forks
1

01 前言 Front Matter

name
mongodb-pro
category
database
description
MongoDB modeling, aggregation pipelines, and operations — use when designing schemas or tuning Mongo queries.

03 SKILL.md 正文

Overview

MongoDB trades rigid schemas for flexible documents, which makes modeling choices — embed vs reference — the central skill. This skill covers schema design, aggregation pipelines, indexing, and the operational basics (replica sets, transactions, backups).

When to use

  • Deciding whether to embed documents or reference across collections
  • Writing aggregation pipelines ($match, $group, $lookup, $unwind)
  • Creating compound, text, geospatial, or TTL indexes
  • Debugging slow queries with explain("executionStats")
  • Setting up replica sets, transactions, or change streams

Core concepts

Model for your queries, not your entities. Embed data that is read together and rarely changes independently (order → line items). Reference data that is shared, large, or updated independently (order → customer). The 16MB document limit and unbounded array growth are the guardrails — an ever-growing embedded array is a schema smell.

Aggregation pipelines are programs. Stages execute in order; put $match and $project early to shrink the working set before expensive stages like $group or $lookup. allowDiskUse saves memory-heavy pipelines from failing, at a speed cost.

Indexes follow the ESR rule. For a query with Equality, Sort, and Range predicates, order compound index fields as Equality → Sort → Range. Prefix compression and index intersection exist, but a purpose-built compound index almost always wins.

Replica sets are mandatory in spirit. Even a single-node "replica set" is required for transactions and change streams. Design for primary/secondary topology: writes go to the primary; tune read preference (secondaryPreferred for analytics) consciously, knowing secondaries can lag.

Transactions exist — use sparingly. Multi-document ACID transactions are available but slower than single-document atomicity, which covers most embedded designs. If you need transactions everywhere, your schema may be too normalized for a document database.

Practical workflow

  1. List your top 10 queries first, with frequency and latency needs — the schema follows from these, not from the ER diagram.
  2. Prototype the pipeline in stages: run each stage in mongosh or Compass and inspect intermediate output; check .explain("executionStats") for COLLSCAN (bad) vs IXSCAN (good).
  3. Index deliberately: create compound indexes matching your hottest queries; use partial indexes (partialFilterExpression) for sparse patterns and TTL indexes for expiring data (sessions, logs).
  4. Guard writes: use schema validation ($jsonSchema) to enforce the fields your code depends on, while leaving the rest flexible.
  5. Monitor: db.serverStatus(), slow query logs, and Atlas-style metrics — watch for growing lock contention, page faults, and replication lag.
  6. Back up with mongodump or snapshots on a schedule, and practice restores; for replica sets, back up from a secondary to avoid primary load.

Common pitfalls

  • Unbounded arrays (e.g. appending every event to a user document forever) — documents bloat, updates rewrite megabytes, and the 16MB cap eventually bites. Cap arrays ($slice) or move to a separate collection.
  • $lookup as a crutch for joins everywhere — occasional lookups are fine; constant cross-collection joins suggest the data should be embedded or the workload belongs in a relational database.
  • No indexes on sort fields — sorting 1M documents in memory fails or crawls; the sort field belongs in the compound index (ESR rule).
  • Treating _id as a string when it's an ObjectId — type mismatches silently return zero results. Query with the correct type.
  • Write concern / read concern left at defaults in systems that need durability guarantees — understand w: "majority" before promising "saved".
  • Storing large binaries in documents — use GridFS or object storage with a reference; documents are for data, not file blobs.

04 同仓库更多 Skills

TanNhatCMS
TanNhatCMS/jarvis

web-scrape

Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open/fetch fails on JS-heavy pages, or when you need clean markdown/structured extraction from a site. Requires FIRECRAWL_API_KEY.

★ 0
TanNhatCMS
TanNhatCMS/jarvis

design-taste-frontend

tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML/CSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, "AI-made", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.

★ 0
TanNhatCMS
TanNhatCMS/jarvis

test-driven-development

Use when implementing any feature or bugfix, before writing implementation code

★ 0
TanNhatCMS
TanNhatCMS/jarvis

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes

★ 0
TanNhatCMS
TanNhatCMS/jarvis

requesting-code-review

Use when completing tasks, implementing major features, or before merging to verify work meets requirements

★ 0
TanNhatCMS
TanNhatCMS/jarvis

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

★ 0