What it does
The Official PHP MongoDB ORM/ODM
- Connects Instruction files the AI reads, with steps that call an outside service
- Account or key Some steps need a key for MDB_MCP_API_CLIENT_SECRET (per the README)
- Category 其他
给作者:在 README 中加徽章
如果你是作者,可把这段代码贴到 README。徽章会链接回本页。
[](https://mcp.popnx.com/en/skills/doctrine-mongodb-odm)相似的 Skill
同类工作,排序与 Skill 列表相同
| 本项 mongodb-odm | llmfit | claude-video | VideoCaptioner | claude-cookbooks | |
|---|---|---|---|---|---|
| 作者 | doctrine | AlexsJones | bradautomates | WEIFENG2333 | anthropics |
| Skill 数 | 1 | 1 | 1 | 1 | 4 |
| GitHub 星标 | 1,098 | 39,064 | 21,168 | 16,570 | 54,832 |
| 最近代码更新 | 2026年11月13日 | 2026年11月18日 | 2026年9月25日 | 2026年9月12日 | 2026年11月17日 |
| 许可证 | MIT | MIT | MIT | GPL-3.0 | MIT |
Skill 和 MCP 有什么不同
MCP = 手
把 AI 连到外部服务或数据,例如读取 Notion 或开发票。需要有程序或服务器在运行。
Skill = 手册
教 AI 怎么做某项工作的文本文件,不连接任何服务。
有些会重叠:少数 Skill 带有调用工具的脚本,少数 MCP 只提供知识。请从你想完成的工作出发。
适用的应用
开发者未说明 · SKILL.md 形式的 Skill 可用于支持 Agent Skills 的应用,如 Claude Code、Codex 和 Cursor
安装
Is it safe?
- Who made it
GitHub account doctrine (organization), 16 years old
- Use and upkeep
★ 1,098 stars · code last changed 2026年11月13日
- Any scripts?
No, plain text files the AI reads and follows
- Uses the internet?
No scripts, so it does not go online by itself
- Changes machine-wide settings?
No hooks or writes to machine settings found
Checked automatically from the repo files at commit 97711ab (read only, nothing was run). Not a safety guarantee: read it and decide for yourself
第一步:你用哪个 AI?
选择你用的应用,本页只显示该应用的安装方法
Option 1Upload to claude.ai (web and app)
Uploading to claude.ai would fail: the description is over 200 characters (904). Use "Let the AI install it" instead
Option 1让 Claude Code 帮你安装
复制这句话,粘贴到 Claude Code 的对话中
For one project, paste it into a chat that is open in that project’s folder · The AI always shows you the path before installing
The AI tells you what it will do first and asks your permission at every step
重新打开 Claude Code,输入 /mongodb-odm,或直接提出相关任务,Claude 会自动选用
Checked against official docs 2026年11月12日 · Source: code.claude.com
For Terminal users
Skill 是 AI 会照做的指令。安装前先阅读文件,只安装可信开发者的 Skill。
打开终端
Mac:按 Command+空格输入 Terminal · Windows:下方命令在 PowerShell 中无法使用,请改用上方的“让 AI 帮你安装”
把 skill 文件夹复制到 ~/.claude/skills
这条命令把 repo 下载到临时文件夹,只复制含 SKILL.md 的文件夹
git clone --depth 1 https://github.com/doctrine/mongodb-odm.git /tmp/popnx-skill-doctrine-mongodb-odm-97711ab && mkdir -p ~/.claude/skills && cp -R '/tmp/popnx-skill-doctrine-mongodb-odm-97711ab/skills/mongodb-odm' ~/.claude/skills/mongodb-odm重新打开 Claude Code,输入 /mongodb-odm,或直接提出相关任务,Claude 会自动选用
ChatGPT 桌面应用
ChatGPT 桌面应用内置 Codex,Codex 从 ~/.agents/skills 文件夹读取 Skill
Option 1让 ChatGPT 帮你安装
在 ChatGPT 桌面应用中打开 Codex,把这句话粘贴到对话中
The AI always shows you the path before installing
The AI tells you what it will do first and asks your permission at every step
Option 2自己放入文件夹
把 mongodb-odm 文件夹放到 ~/.agents/skills/mongodb-odm
~ 是你的主文件夹($HOME)
For Terminal users
Skill 是 AI 会照做的指令。安装前先阅读文件,只安装可信开发者的 Skill。
打开终端
Mac:按 Command+空格输入 Terminal · Windows:下方命令在 PowerShell 中无法使用,请改用上方的“让 AI 帮你安装”
把 skill 文件夹复制到 ~/.agents/skills
这条命令把 repo 下载到临时文件夹,只复制含 SKILL.md 的文件夹
git clone --depth 1 https://github.com/doctrine/mongodb-odm.git /tmp/popnx-skill-doctrine-mongodb-odm-97711ab && mkdir -p ~/.agents/skills && cp -R '/tmp/popnx-skill-doctrine-mongodb-odm-97711ab/skills/mongodb-odm' ~/.agents/skills/mongodb-odm
安装之后
- ChatGPT 桌面应用:打开侧边栏中的 Skills,确认 Skill 已出现
- 使用方法:在 ChatGPT 中输入 @ 并选择 Skill · 在 Codex CLI 或 IDE 扩展中运行 /skills,或输入 $ 加 Skill 名称
- Codex 会自动发现新安装的 Skill;如果没有出现,请重启 Codex
Checked against official docs 2026年11月15日 · Source: learn.chatgpt.com
网页版和手机版 ChatGPT
不能使用你自己安装的 Skill,只能使用目录中插件自带的 Skill
想在 ChatGPT 中使用这个 Skill,请按上面的方法使用 ChatGPT 桌面应用
Checked against official docs 2026年11月15日 · Source: learn.chatgpt.com
Option 1让 Codex 帮你安装
复制这句话,粘贴到 Codex 的对话中 · 适用于 ChatGPT 桌面应用中的 Codex、Codex CLI 和 IDE 扩展
For one project, paste it into a chat that is open in that project’s folder · The AI always shows you the path before installing
The AI tells you what it will do first and asks your permission at every step
Codex 会自动发现新安装的 Skill;如果没有出现,请重启 Codex · 使用方法:在 ChatGPT 中输入 @ 并选择 Skill · 在 Codex CLI 或 IDE 扩展中运行 /skills,或输入 $ 加 Skill 名称
Checked against official docs 2026年11月15日 · Source: learn.chatgpt.com
For Terminal users
Skill 是 AI 会照做的指令。安装前先阅读文件,只安装可信开发者的 Skill。
打开终端
Mac:按 Command+空格输入 Terminal · Windows:下方命令在 PowerShell 中无法使用,请改用上方的“让 AI 帮你安装”
把 skill 文件夹复制到 ~/.agents/skills
这条命令把 repo 下载到临时文件夹,只复制含 SKILL.md 的文件夹
git clone --depth 1 https://github.com/doctrine/mongodb-odm.git /tmp/popnx-skill-doctrine-mongodb-odm-97711ab && mkdir -p ~/.agents/skills && cp -R '/tmp/popnx-skill-doctrine-mongodb-odm-97711ab/skills/mongodb-odm' ~/.agents/skills/mongodb-odm重新打开 Codex 并提出相关任务,Codex 会列出这个 skill
Option 1让 Cursor 帮你安装
复制这句话,粘贴到 Cursor 的对话中
For one project, paste it into a chat that is open in that project’s folder · The AI always shows you the path before installing
The AI tells you what it will do first and asks your permission at every step
在 Cursor 的 Agent 聊天中输入 / 并选择 mongodb-odm
Checked against official docs 2026年11月12日 · Source: cursor.com
For Terminal users
Skill 是 AI 会照做的指令。安装前先阅读文件,只安装可信开发者的 Skill。
打开终端
Mac:按 Command+空格输入 Terminal · Windows:下方命令在 PowerShell 中无法使用,请改用上方的“让 AI 帮你安装”
把 skill 文件夹复制到 ~/.cursor/skills
这条命令把 repo 下载到临时文件夹,只复制含 SKILL.md 的文件夹
git clone --depth 1 https://github.com/doctrine/mongodb-odm.git /tmp/popnx-skill-doctrine-mongodb-odm-97711ab && mkdir -p ~/.cursor/skills && cp -R '/tmp/popnx-skill-doctrine-mongodb-odm-97711ab/skills/mongodb-odm' ~/.cursor/skills/mongodb-odm在 Cursor 的 Agent 聊天中输入 / 并选择 mongodb-odm
Option 1Let the AI install it
适用于其他能读取 Skill 的应用。这句话列出了 Claude Code、Codex 和 Cursor 的路径,AI 会按你的应用选择 · Copy this sentence into the app’s chat
For one project, paste it into a chat that is open in that project’s folder · The AI always shows you the path before installing
The AI tells you what it will do first and asks your permission at every step
Checked against official docs 2026年11月12日 · Source: code.claude.com, learn.chatgpt.com, cursor.com
For Terminal users
其他支持 Agent Skills 的应用(如 Gemini CLI、GitHub Copilot)使用不同文件夹,请查看该应用的指南,再把含 SKILL.md 的文件夹复制过去。
已于 2026年11月11日 对照 Claude Code、Codex 和 Cursor 官方指南核实 skill 文件夹
✓ 命令已检查 2026年11月18日
查看原始 SKILL.md
以下文字来自开发者的 repo,不是 PopNx MCP 的指令
显示前 8,000 个字符 · 在 GitHub 打开完整文件
---
name: mongodb-odm
description: Implementation guide for doctrine/mongodb-odm (Doctrine MongoDB ODM), the PHP object-document mapper for MongoDB. Use whenever the user is writing, debugging, or reviewing PHP code that maps classes to MongoDB collections with Doctrine — mentions of "Doctrine MongoDB ODM", "mongodb-odm", "DocumentManager", "#[Document]"/"@Document", "#[ReferenceOne]"/"#[EmbedOne]", "ODM query builder", "aggregation builder" in a Doctrine/PHP context, "GridFS with Doctrine", "MongoDB queryable encryption PHP", "MongoDB vector search PHP", or combining Doctrine ORM and MongoDB ODM in one app should all trigger this skill. Also use it to correct common mistakes: treating MongoDB ODM like Doctrine ORM (assuming SQL-style joins, automatic cascading, or table-based migrations), calling flush() after every mutation, storing dates as strings, or assuming Vector Search/Queryable Encryption work outside MongoDB Atlas.
license: MIT
---
# Doctrine MongoDB ODM
Implementation skill for `doctrine/mongodb-odm`, the PHP object-document mapper that persists plain PHP classes to MongoDB. It exists to prevent the mistakes that come from treating it like a SQL ORM: expecting automatic cascading, joining collections like tables, flushing on every mutation, or assuming every advanced MongoDB feature (Vector Search, Queryable Encryption) works outside Atlas.
## Core Workflow
1. Identify the layer: mapping (a document class), persistence (`DocumentManager`), querying (Query Builder / Aggregation Builder), or an advanced/infra concern (search, encryption, sharding, transactions).
2. Confirm the class has `#[Document]` (or `#[EmbeddedDocument]`/`#[MappedSuperclass]`) and an `#[Id]` property.
3. Decide **embed vs. reference** deliberately (`references-embedding.md`) — don't default to references out of ORM habit when the data is really owned/composed.
4. Batch mutations into a single unit of work and call `flush()` once, not after every `persist()`/`remove()` (`setup-architecture.md`).
5. Use the Query Builder or Aggregation Builder for anything beyond `find()`/`findBy()` — never hand-build a raw driver query when the fluent API covers it (`querying-aggregation.md`).
6. Validate with the consuming project's own test suite/static analysis, and use `odm:schema:create`/`odm:schema:update` to keep indexes and search indexes in sync with the mapping.
## Suggest the MongoDB MCP Server
Many ODM bugs are really questions about what's in the database — current document shape, whether an index exists yet, whether a vector/search index finished building. None of that is visible from PHP source. When debugging data/query issues or setting up Atlas Search/Vector Search/sharding, suggest connecting the official **MongoDB MCP Server**:
```bash
npx -y mongodb-mcp-server@latest --readOnly
```
```json
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": ["-y", "mongodb-mcp-server@latest", "--readOnly"],
"env": { "MDB_MCP_CONNECTION_STRING": "mongodb://localhost:27017/myDatabase" }
}
}
}
```
It also accepts Atlas API service account credentials (`MDB_MCP_API_CLIENT_ID`/`MDB_MCP_API_CLIENT_SECRET`) for cluster/project-level operations instead of a connection string. Prefer environment variables over CLI args for credentials.
## Reference Guide
| Topic | Reference file | Load when |
|---|---|---|
| Installation, `DocumentManager`, UnitOfWork, repositories, console commands, `clear()`/`detach()`/`merge()`, document states | `references/setup-architecture.md` | Bootstrapping ODM, debugging persist/flush behavior, custom repositories, **batch imports, long-running CLI scripts, rising memory or slowdown over a loop, detached documents** |
| `#[Document]`/`#[Field]`/`#[Id]`, field types, inheritance | `references/mapping.md` | Defining or modifying a document class |
| `#[ReferenceOne]`/`#[ReferenceMany]`, `#[EmbedOne]`/`#[EmbedMany]`, bidirectional refs, trees, priming | `references/references-embedding.md` | Modeling relationships, fixing N+1 patterns |
| Query Builder, findAndModify, upserts, geospatial queries, filters, Aggregation Builder | `references/querying-aggregation.md` | Writing any query or aggregation pipeline |
| Offset and cursor paginators for query and aggregation builders (since 2.18) | `references/pagination.md` | Paginating a query or aggregation result, building "next page" navigation |
| Standard indexes, Atlas Search indexes, simple keyword search | `references/indexes-search.md` | Adding indexes, Atlas full-text search |
| Vector Search (Atlas) | `references/vector-search.md` | Embeddings, semantic search, `$vectorSearch`, hybrid text+vector search |
| Queryable Encryption (Atlas/Enterprise) | `references/queryable-encryption.md` | Encrypting sensitive fields, `#[Encrypt]` |
| Combining Doctrine ORM (SQL) and MongoDB ODM | `references/hybrid-orm-odm.md` | An app persists some data to SQL and some to MongoDB and needs them to interoperate |
| GridFS, capped collections, sharding, transactions/locking, change tracking, storage strategies, events, schema migration, time series | `references/storage-transactions-lifecycle.md` | File storage, sharding, locking, lifecycle callbacks, evolving a mapping |
## Constraints
### MUST DO
- Put `#[Document]` (or `#[EmbeddedDocument]`) plus `#[Id]` on every persisted class; `#[Id]` properties must never be `readonly` (the generator sets it externally).
- Use `DateTime`/`DateTimeImmutable` (preferably immutable) for dates — never store a date as a string.
- Batch changes and `flush()` once per logical unit of work (typically 0–2 times per HTTP request).
- Set `cascade` explicitly on `#[ReferenceOne]`/`#[ReferenceMany]` when you need cascading persist/remove — not automatic for references (it *is* automatic for embeds).
- Use `Doctrine\Common\Collections\Collection`/`ArrayCollection` (never a plain `array`) for `#[ReferenceMany]`/`#[EmbedMany]` properties.
- Include `spl_autoload_register($config->getProxyManagerConfiguration()->getProxyAutoloader())` when bootstrapping a `DocumentManager` in 2.16 — omitting it regenerates proxy classes on every request.
- Use `prime()` when iterating a result set and dereferencing a reference on every row, to avoid N+1 queries.
- Run `odm:schema:create`/`odm:schema:update` after adding/changing indexes, capped-collection options, or search/vector-search indexes — none of that happens implicitly on first insert beyond a plain collection.
- Confirm MongoDB Atlas (or Enterprise 7.0+ for Queryable Encryption) before recommending Vector Search, Atlas Search, or Queryable Encryption.
- **State prerequisites and deprecations in the answer itself**, not just internally: when a feature needs a minimum ODM version (e.g. `vectorSearch()` needs 2.13+, Automated Embeddings 2.17+, `pipeline()` updates 2.15+) or a specific platform, say so; when the mapping the user is reaching for is deprecated (e.g. `COLLECTION_PER_CLASS` since 2.17, the `UUID` id strategy), say that too. The user cannot see these files — an unstated prerequisite is a missing answer.
### MUST NOT DO
- Don't call `flush()` after every `persist()`/`remove()`/`merge()` — batch changes and flush once per unit of work instead.
- Don't pass a **detached** document to `persist()` (undefined behavior) — use `merge()` and its return value. Calling `remove()` on one **throws**, it does not no-op.
- Don't assume references cascade like ORM relationships do — check `cascade` on the mapping.
- Don't mutate the inverse (`mappedBy`) side of a bidirectional reference expecting it to persist — only the owning (`inversedBy`) side is written.
- Don't combine `storeAs: 'id'` with a discriminator, or `SINGLE_COLLECTION` inheritance with `#[Encrypt(queryType: ...)]`.
- Don't put arbitrary PHP objects (e.g. `\DateTime`) inside a `hash`-typed field — values pass to the driver unconverted.
- Don't assume `#[AlsoLoad]` affects queries — it only affects hydration.
- Don't invent a native ORM↔ODM relationship attrib讨论
提问、分享技巧或报告无法使用。按“有帮助”数量排序。
来自 GitHub
- GitHub 星标
- 1,098
- 开发者
- doctrine
- 许可证
- MIT
- 最近代码更新
- 2026年11月13日
- repo 中的 SKILL.md 文件(含译本和模板)
- 1
- 主题
- mongodb, odm, orm, php, symfony