Skip to content
Back to skills

Database Mongodb

ASecurity

Design it from the read path first: - If posts are read with only a small, bounded preview of comments, keep `posts` and `comments` in separate collections and optionally embed a tiny cached summary on the post document. - Do not embed all comments directly inside the post if each post can accumulate many comments over time. That creates an unbounded array, larger documents, slower writes, and eventually document-size pressure. A practical schema is: ```js // posts { _id: ObjectId, authorId: ...

  • 584 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 5, 2026
development

Security analysis

A100/100

Pro scans all 11 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill database-mongodb --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Database Mongodb?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Database Mongodb
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-database-mongodb-agent-skills-standard/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-database-mongodb-agent-skills-standard)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
Design it from the read path first:

- If posts are read with only a small, bounded preview of comments, keep `posts` and `comments` in separate collections and optionally embed a tiny cached summary on the post document.
- Do not embed all comments directly inside the post if each post can accumulate many comments over time. That creates an unbounded array, larger documents, slower writes, and eventually document-size pressure.

A practical schema is:

```js
// posts
{
  _id: ObjectId,
  authorId: ObjectId,
  title: String,
  body: String,
  commentCount: Number,
  latestComments: [
    {
      _id: ObjectId,
      authorId: ObjectId,
      bodyPreview: String,
      createdAt: Date
    }
  ], // bounded preview only
  createdAt: Date,
  updatedAt: Date
}

// comments
{
  _id: ObjectId,
  postId: ObjectId,
  authorId: ObjectId,
  body: String,
  createdAt: Date,
  updatedAt: Date
}
```

Why this shape works:

- Comments have unbounded growth, so they should have an independent lifecycle.
- Posts and comments can scale separately.
- You can fetch the post first, then query comments by `postId`.
- A bounded `latestComments` preview improves common reads without storing the full comment history inline.

Indexes should match real queries:

```js
db.comments.createIndex({ postId: 1, createdAt: -1 })
db.posts.createIndex({ authorId: 1, createdAt: -1 })
```

The `comments` index supports the common access pattern:

- equality: `postId`
- sort: `createdAt`

That follows the equality -> sort -> range principle for compound indexes.

Typical reads:

```js
db.posts.findOne({ _id: postId })

db.comments
  .find({ postId })
  .sort({ createdAt: -1 })
  .limit(20)
```

If you need threaded replies, avoid deep recursive nesting in a single document. Instead store:

```js
{
  _id,
  postId,
  parentCommentId: ObjectId | null,
  ...
}
```

Then index for that access pattern too:

```js
db.comments.createIndex({ postId: 1, parentCommentId: 1, createdAt: 1 })
```

In short: embed only bounded comment summaries that are read with the post, but store the actual comments in a separate collection because “many comments” implies unbounded growth and a separate lifecycle.

Files in this skill

  • eval-1.baseline.md1.9 KB
  • eval-1.with-skill.md2.1 KB
  • eval-2.baseline.md2.6 KB
  • eval-2.with-skill.md3.6 KB
  • eval-3.baseline.md1.8 KB
  • eval-3.with-skill.md2.2 KB
  • trigger-1.md163 B
  • trigger-2.md132 B
  • trigger-3.md131 B
  • trigger-4.md130 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.