Resolve Issue #3542043: Allow compatibility with ext-mongodb version 2.0
Summary
Allows the module to be installed alongside version 2.x of the ext-mongodb extension and the mongodb/mongodb library, and keeps support for 1.x.
Changes
-
Composer constraints: the root
composer.jsonand themongodb,mongodb_storageandmongodb_watchdogsubmodule files now require:ext-mongodb:^1.5.1 || ^2.0mongodb/mongodb:^1.13 || ^2.0
Composer picks the library version that matches the installed extension.
-
Logger::eventCollections(): the return type changes fromMongoDB\Model\CollectionInfoIteratorto\Iterator. The 2.0 library removedCollectionInfoIterator, andDatabase::listCollections()now returns a plainIterator. In 1.x,CollectionInfoIteratorextendsIterator, so the new type works with both versions. -
docs/install.md: now says the 2.x extension is supported.
Compatibility review
I compared the module against the 2.0 upgrade guides for the library and the extension. No other changes are needed:
- The module never uses the return values of
drop()orcreateCollection(), which now returnvoid. - The
bsonUnserialize()implementations already declare: void. new UTCDateTime()always gets anint. Strings and floats are no longer accepted.- The module doesn't use
mapReduce(), the removed BSON functions, integerReadPreferencemodes, or the removed find, query or driver options.
CI
.gitlab-ci.yml is unchanged. The composer step now resolves mongodb/mongodb 2.x, which matches the 2.x extension that pecl install mongodb installs in the phpunit job. Before this change, CI installed the 1.x library alongside the 2.x extension.
API changes
Logger::eventCollections() now declares \Iterator as its return type. Callers that only iterate the result are not affected.
Testing
- Composer resolves
mongodb/mongodb2.4.2 withext-mongodb2.5.2, and still resolves 1.21.5 when the 1.x library is requested. - Test suite passes on CI (ext 2.x + library 2.x).
- Manual test with ext 1.x + library 1.x.
AI disclosure
This MR was engineered using Claude Code throughout coding the solution, with human edits, manual review and decisions made independently, per Drupal.org's AI contribution policy.
Closes #3542043