mongo-php-library
AGENTS.md1.6k starsChanged 10 months agoApache-2.0View on GitHub
The official high-level MongoDB PHP library (mongodb/mongodb). It provides a full-featured, typed API — clients, databases, collections, GridFS, change streams, bulk writes, codecs — on top of the low-level mongodb extension. The extension is a separate repository (mongodb/mongo-php-driver). It owns the wire protocol, connection management, and BSON encoding. This library builds the server commands and implements the operation-level behaviour on top. A change to how a command is executed or how BSON is encoded belongs in the extension; a change…
Adopted by
Steady: 0 new projects took it in the last 4 weeks, none the 4 weeks before.thin data
Who's talking about mongodb/mongo-php-library
- DataDog/dd-trace-php“New MongoDB driver integration”GitHub · Jul 19, 2019 · 11 reactions
- doctrine/mongodb-odm“[2.0] Replace doctrine/mongodb for mongodb/mongodb and ext-mongodb”GitHub · Jan 23, 2017 · 11 reactions
- Stack Overflow“how to check validation mongodb id with php”Stack Overflow · Sep 14, 2016 · 10 votes
- Stack Overflow“Laravel Homestead Mongo install causing PHP error undefined symbol: php_json_serializable_ce in Unknown on …”Stack Overflow · Dec 5, 2016 · 6 votes
- doctrine/mongodb-odm“[RFC] Plan for MongoDB ODM v3”GitHub · Apr 29, 2025 · 5 reactions
The biggest 5 of 75 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 75
Talked about on GitHub and Stack Overflow (75 times).
On GitHub · 50
- Jul 19, 2019New MongoDB driver integration — DataDog/dd-trace-php11 reactions · 13 comments
- Jan 23, 2017[2.0] Replace doctrine/mongodb for mongodb/mongodb and ext-mongodb — doctrine/mongodb-odm11 reactions · 10 comments
- Apr 29, 2025[RFC] Plan for MongoDB ODM v3 — doctrine/mongodb-odm5 reactions · 6 comments
- Jun 19, 2023Laravel 9 mongodb driver issue inside docker — mongodb/laravel-mongodb4 reactions · 1 comment
- Dec 12, 2023Major slowdown since version 1.17.0 — mongodb/mongo-php-driver2 reactions · 8 comments
45 more on GitHub
- Aug 29, 2023Reformat RST for Atlas Search prose tests — mongodb/specifications1 reaction
- Nov 5, 2018[Travis] Bump ext-mongodb to 1.5.2 on Travis — symfony/symfony1 reaction · 6 comments
- Apr 11, 2018mongodb extension to 1.4.0 — laravel/homestead1 reaction · 2 comments
- Nov 11, 2016Crash on Windows with PHP7 (&7.1) — mongodb/mongo-php-driver1 reaction · 29 comments
- Nov 5, 2026DRIVERS-3699: top-level err halts client bulkWrite exec — mongodb/specifications0 reactions · 2 comments
- Nov 4, 2026chore(deps): bump mongodb/mongodb from 2.3.0 to 2.4.2 in the composer group across 1 directory — askeita/certibot0 reactions
- Nov 3, 2026Bump mongodb/mongodb from 2.0.0 to 2.5.0 — epictetushmu/E-Lib0 reactions · 1 comment
- Nov 2, 2026Bump mongodb/mongodb from 2.0.0 to 2.5.0 — nikitasmen/E-Lib0 reactions · 1 comment
- Nov 2, 2026Bump mongodb/mongodb from 2.1.2 to 2.5.0 — phalcon/incubator-session0 reactions
- Oct 31, 2026Bump mongodb/mongodb from 2.1.0 to 2.4.2 in /modules/mongodb — ihsn/nada0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.10.0 to 2.5.0 in /持续搞【附近的人】---听说MongoDB是专业的(三) — elarity/wechat-official-accounts-demo-code0 reactions
- Oct 13, 2026Bump the composer group across 2 directories with 1 update — AlkisAzna/iXenOnK8s0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.21.3 to 2.5.0 — rkeplin/bible-php-api0 reactions
- Oct 13, 2026chore(deps): Bump mongodb/mongodb from 1.17.0 to 2.5.0 in /src — kazordoon/php-login-mongodb0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 2.3.0 to 2.4.2 in /backend in the composer group across 1 directory — Fine71/vite_et_gourmand0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.6.0 to 2.5.0 — Bassel-kh/php-primer-test0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.7.0 to 2.5.0 — leobel/fivo-landing0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.21.1 to 2.5.0 — wekan/php0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.20.0 to 2.5.0 — SMaitriya/PlanningMongodb0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 2.3.0 to 2.4.2 — eman-development-design/mongodb-helpers0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.4.2 to 2.5.0 — Azouu/Kajika0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 2.0.0 to 2.4.2 — xibosignage/xibo-cms0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.15.0 to 2.5.0 in /ecf_arkadia in the composer group across 1 directory — bouzelmat/Ecf_Arkadia0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 2.1.2 to 2.4.2 in the composer group across 1 directory — MowlandCodes/CRUD_PHP_MONGODB_BASDAT_20 reactions
- Oct 13, 2026chore(deps): bump mongodb/mongodb from 2.4.1 to 2.4.2 in the composer group across 1 directory — Potato-Technical/miniticket0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 2.1.2 to 2.4.2 — Cvar1984/VRChessIndonesia0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 2.3.0 to 2.4.2 — ecxof/Event-Management-Website0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 2.0.0 to 2.4.2 — gouda-tijdmachine/lod-pijplijn0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 2.1.0 to 2.4.2 — SamuelTallet/MongoDB-PHP-GUI0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.12.0 to 2.5.0 — Vustron/PHP-OOP-MongoDB-CRUD0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.12.0 to 2.5.0 — sherwin-roger0/guvi0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.13.0 to 2.5.0 in /php_examples/voicenotes — revdotcom/revai-examples0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.10.0 to 2.5.0 in /public/php — wekan/php0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.10.0 to 2.5.0 — singh-ripudaman/database_project0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.12.0 to 2.5.0 — TheMaksoo/SolyxWebGame0 reactions
- Oct 13, 2026Build(deps): Bump mongodb/mongodb from 2.1.1 to 2.5.0 — BaptFr/ConsoNum0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 1.11.0 to 2.5.0 — alexpts/php-mongo-repository0 reactions
- Oct 13, 2026Bump mongodb/mongodb from 2.3.0 to 2.4.2 — TheAxisEpicSauce/Fetcher0 reactions
- Oct 9, 2026Bump the composer-minor-patch group across 1 directory with 2 updates — Tolemak/LectureBackend_BackendDemo0 reactions
- Oct 2, 2026Update dependency mongodb/mongodb to v2.4.2 [SECURITY] — patchlevel/odm0 reactions · 1 comment
- Sep 15, 2026Bump mongodb/mongodb from 2.1.2 to 2.4.2 — banerjeesangita/guvi-web-app0 reactions
- Sep 9, 2026Update dependency mongodb/mongodb to v2 [SECURITY] — laminas/laminas-cache-storage-adapter-ext-mongodb0 reactions · 1 comment
- Sep 8, 2026build(deps): bump mongodb/mongodb from 1.11.0 to 1.21.4 — BobLiu0518/BLBot0 reactions
- May 22, 2026pie install of 2.3.3 fails — mongodb/mongo-php-driver0 reactions · 2 comments
- May 13, 2025Saving into a collection with 54 character name returns exception — mongodb/mongo-php-driver0 reactions · 2 comments
On Stack Overflow · 25
- Sep 14, 2016how to check validation mongodb id with php10 votes
- Dec 5, 2016Laravel Homestead Mongo install causing PHP error undefined symbol: php_json_serializable_ce in Unknown on line 06 votes · 2 answers
- Jun 3, 2016Executing MongoDB Aggregate Operation in PHP3 votes
- Feb 23, 2016Installing the PHP 7 MongoDB Client/Driver?3 votes
- Sep 28, 2017MapReduce with PHP and MongoDB2 votes · 1 answer
20 more on Stack Overflow
- Apr 7, 2017How to solve Fatal error: Class 'MongoClient' not found?2 votes
- Oct 17, 2016Install phpMongo Drivers on windows2 votes · 1 answer
- Jan 31, 2016how to get older versions of mongodb?2 votes · 2 answers
- Jan 30, 2016How to use the MongoDB group function via the new PHP pecl/mongodb driver (1.1.2) and library2 votes · 2 answers
- Apr 2, 2019PHP MongoDB\Model\BSONDocument does not make a reflection1 vote
- Apr 28, 2016How to properly convert MongoDB BSON into PHP Object1 vote · 1 answer
- Feb 17, 2016Difference between mongodb driver for PHP and mongodb database driver1 vote
- Feb 14, 2016How to connect to SSL enabled MongoDB with the PHP userland library?1 vote
- Dec 7, 2022php mongodb on BulkWriteException get Additional information0 votes · 1 answer
- Jul 7, 2021Mongodb driver which version work gridfs for php0 votes
- Sep 3, 2020I can't use php with mongodb sixtaxe error?0 votes
- Feb 10, 2020PHP MongoDB update multiple fields with one query0 votes
- Dec 2, 2017Use of pattern $match $in in aggregate function of Mongo PHP Library0 votes · 1 answer
- Jun 28, 2017PHP MongoDB\Driver - how to request original document as return value after doing an update0 votes
- Apr 4, 2017How to get affected number of rows using mongodb ,php driver0 votes
- Nov 17, 2016Mac OS X MongoDB and MONGO PHP DRIVER0 votes
- Oct 18, 2016Mongo db client library in drupal 7 module without composer0 votes · 1 answer
- Mar 15, 2016Mongodb "auth fails" with mongodb php driver and new php library0 votes · 2 answers
- Jan 18, 2016Can't query with mongodb-1.1.x php driver0 votes
- May 21, 2016PHP 7 and MongoDB Driver-1 votes
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 31,439 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
The file
We split this AGENTS.md into the rules it gives an agent
11 rules. About 0 are common, 5 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 56
Call the vendor/bin/ binaries directly rather than the composer run aliases, so you can pass each tool's own options.
- Distinctive: line 68
If a suite you need requires a variable that is not set, stop and tell the user which one, rather than working around it.
- Very specific: line 90
Don't add native parameter or return types to existing public or protected methods in src/ — those signatures are covered by the BC …
- Very specific: line 95
Prefer $array['key'] ?? $default over isset() for default values.
- Very specific: line 96
Run vendor/bin/phpcbf before committing, then verify with vendor/bin/phpcs.
- Very specific: line 113
Don't mark $options, documents to insert or replace, names (database, collection, index, field), or a value the library puts into a query …
- Distinctive: line 117
Add the annotation when adding such a method or parameter.
- Distinctive: line 129
Keep comments to a short line or two.
- Very specific: line 130
Don't add PHPDoc that only repeats the native signature.
- Distinctive: line 154
Keep PR descriptions and review replies short — one to three sentences.
- Distinctive: line 156
After a push, say what changed and why.
≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md - MongoDB PHP Library
This file provides guidance to AI coding agents when working with code in this repository.
Overview
The official high-level MongoDB PHP library (mongodb/mongodb). It provides a
full-featured, typed API — clients, databases, collections, GridFS, change
streams, bulk writes, codecs — on top of the low-level mongodb extension.
The extension is a separate repository (mongodb/mongo-php-driver). It owns the wire protocol, connection management, and BSON encoding. This library builds the server commands and implements the operation-level behaviour on top. A change to how a command is executed or how BSON is encoded belongs in the extension; a change to how a command is constructed or how an operation behaves belongs here.
Correctness, backwards compatibility, and conformance to the MongoDB Driver Specifications are top priorities.
- Issue tracker: JIRA PHPLIB project. GitHub Issues is not used for bugs or features.
- Branches:
v2.xis the default, where new features and optimisations land. The latestvX.Yminor branch takes bug fixes and maintenance tasks.v1.21receives only critical bug fixes. - Requires the
mongodbextension — seecomposer.jsonfor the PHP andext-mongodbversions supported on this branch.
Tech Stack
- PHP library distributed via Composer, with
declare(strict_types=1)and full type declarations throughout. - Testing: PHPUnit (
phpunit/phpunit), installed as a direct dev dependency — there is no Symfony PHPUnit Bridge. - Static analysis: Psalm, level 1, with
psalm-baseline.xmlcovering pre-existing issues. Fix new errors rather than baselining them. - Coding standards: PHP_CodeSniffer (
phpcs.xml.dist). - Refactoring: Rector (
rector.php).
Project Structure
src/— the library. Key areas:Builder/(aggregation pipeline stages and query builders),Codec/,Command/(database commands),Exception/,GridFS/,Model/(BSON document models),Operation/(one class per server operation),ValueObject/.tests/— PHPUnit tests mirroringsrc/.SpecTests/andUnifiedSpecTests/are JSON/YAML-driven cross-driver spec tests with shared runners.tests/specifications/andtests/drivers-evergreen-tools/— git submodules, updated by Dependabot. Rungit submodule update --initafter cloning.generator/— code generator forsrc/Builder/(stages, query and update operators, accumulators, expressions) and the matchingtests/Builder/*/Pipelines.php. A separate subproject, not part of the distributed package. It does not generatesrc/Operation/. Any file whose header readsTHIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST!is generated — edit the generator or its config instead, then regenerate.tools/,benchmark/,examples/— helper scripts, PHPBench benchmarks, and runnable examples (the examples are also executed by the test suite).
Commands
composer update # install dependencies and initialize the submodules
vendor/bin/phpunit # run the test suite
vendor/bin/phpcs # coding standards
vendor/bin/phpcbf # auto-fix coding-standard violations
vendor/bin/psalm # static analysis
vendor/bin/rector --dry-run # preview refactors
vendor/bin/rector # apply refactorsCall the vendor/bin/ binaries directly rather than the composer run aliases, so
you can pass each tool's own options. Run a single test file or filter with, e.g.
vendor/bin/phpunit tests/Collection/CollectionFunctionalTest.php --filter testGetNamespace.
Testing
- Tests require a running MongoDB server.
phpunit.xml.distdefaults toMONGODB_URI=mongodb://127.0.0.1:27017/?serverSelectionTimeoutMS=100andMONGODB_DATABASE=phplib_test; override them in a localphpunit.xmlor via the environment. - Authentication, stable-API, load-balancer, and CSFLE suites need additional environment variables. The complete list is in CONTRIBUTING.md. If a suite you need requires a variable that is not set, stop and tell the user which one, rather than working around it.
- Atlas Search tests are tagged
#[Group('atlas')]and are gated byFunctionalTestCase::isAtlas(), which only recognises a connection string whose host ends in.mongodb.netor.mongodb-dev.net. Against a local server they skip silently — a green run is not validation. CI provisions a real Atlas cluster; to run them locally, pointMONGODB_URIat Atlas, or at Atlas Local in Docker behind a hostname matching that guard. - Spec tests come from the
tests/specificationssubmodule. When a submodule bump causes failures, follow "Handling test failures on updates" in CONTRIBUTING.md: skip a test only when it exercises a specification or runner feature that is not implemented yet, or when it exposes a spec bug too large to fix here. Fix small spec bugs in the same PR. Don't blanket-skip — a skip can hide a real library regression. tests/DocumentationExamplesTest.phpruns the snippets published in the PHP library manual; keep them in sync when public behaviour changes.
Code Conventions
- Minimum supported PHP version is in
composer.json; code must work on that version and newer. Usedeclare(strict_types=1), native type declarations on new code, and PHPDoc for generics and array shapes where native types cannot express them. - Don't add native parameter or return types to existing public or protected
methods in
src/— those signatures are covered by the BC promise, and adding a type breaks downstream overrides that omit it (e.g.Client::getManager()).phpcs.xml.distexemptssrc/from the mandatory-native-return-type rule for this reason; new code andtests/do require native types. - Prefer
$array['key'] ?? $defaultoverisset()for default values. - Run
vendor/bin/phpcbfbefore committing, then verify withvendor/bin/phpcs. .github/copilot-instructions.mddocuments the review expectations for PHP version, typing, and BSON handling.
Taint Analysis Annotations
Applications find NoSQL injection with Psalm's
taint analysis, which doesn't look
inside vendor/: it only sees the annotations on the methods they call. So every
public method of Client, Database, Collection, ClientBulkWrite and GridFS
Bucket that sends a parameter to the server as a query document marks it with
@psalm-taint-sink nosql $param.
- Mark filters, update documents and pipelines, aggregation pipelines, database
commands and lists of bulk write operations. A request like
?name[$ne]=turns a value into an operator document, so any of these built from user input is an injection. - Don't mark
$options, documents to insert or replace, names (database, collection, index, field), or a value the library puts into a query under$eq, such as the$idof the GridFS methods: none of them can change which documents a query matches. - Add the annotation when adding such a method or parameter.
Code Comments
Comments are the exception, not the default — well-named classes, methods, and variables should carry the meaning. Add one only where the code cannot explain itself.
- Comment the why, never the what: a non-obvious constraint, a server quirk, a workaround for an upstream bug. Don't narrate the next line.
- Describe the code as it is, not how it came to be. No references to the change, the ticket, the PR, the review, or a previous version — that belongs in the commit message or PR description.
- Keep comments to a short line or two; a longer rationale belongs in the PR or docs.
- Don't add PHPDoc that only repeats the native signature; use it for what types
can't express (array shapes, generics,
@throws).
Commit and PR Conventions
- Prefix commit messages and PR titles with the JIRA key:
PHPLIB-1234: Short description. - Target the oldest maintained branch the change applies to — the latest
vX.Yminor branch for bug fixes and maintenance,v2.xfor features and optimisations; themerge-upworkflow propagates fixes to newer branches. - Push the branch to your own fork and open the pull request from there.
- Open pull requests as drafts, and let a maintainer mark them ready once reviewed.
- Fill in
.github/PULL_REQUEST_TEMPLATE.mdand apply exactly one release label:feature,bug,minor,security, ortidy.minorand above appear in the release notes;tidydoes not. Call out breaking changes explicitly. Don't add a "Test plan" section. - The library follows semantic versioning — never break backwards compatibility in a non-major release. See RELEASING.md.
- User documentation lives in mongodb/docs-php-library, not in this repository.
PR descriptions and comments
- Keep PR descriptions and review replies short — one to three sentences. Write in plain English.
- After a push, say what changed and why. Don't list the checks, tests, or PHP versions you ran; CI reports those.
- Reply to a review comment only to answer it or to say how it was resolved.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

