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.json and the mongodb, mongodb_storage and mongodb_watchdog submodule files now require:

    • ext-mongodb: ^1.5.1 || ^2.0
    • mongodb/mongodb: ^1.13 || ^2.0

    Composer picks the library version that matches the installed extension.

  • Logger::eventCollections(): the return type changes from MongoDB\Model\CollectionInfoIterator to \Iterator. The 2.0 library removed CollectionInfoIterator, and Database::listCollections() now returns a plain Iterator. In 1.x, CollectionInfoIterator extends Iterator, 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() or createCollection(), which now return void.
  • The bsonUnserialize() implementations already declare : void.
  • new UTCDateTime() always gets an int. Strings and floats are no longer accepted.
  • The module doesn't use mapReduce(), the removed BSON functions, integer ReadPreference modes, 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/mongodb 2.4.2 with ext-mongodb 2.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

Edited by Matt Hand

Merge request reports

Loading
Loading