alcaeus/mongo-php-adapter
Compatibility layer that lets legacy PHP MongoDB drivers (ext-mongo) work with the newer mongodb extension and library. Helps modernize apps with minimal code changes by translating old APIs to the current MongoDB PHP driver.
alcaeus/mongo-php-adapter bridges the deprecated ext-mongo PHP extension with the modern mongodb/mongodb library, enabling legacy applications to migrate incrementally. This is valuable for teams maintaining older Laravel applications (pre-5.4+) that rely on MongoDB via the deprecated extension.jenssegers/laravel-mongodb) is built on mongodb/mongodb, so this adapter could serve as a transitional layer for refactoring legacy MongoDB logic without rewriting entire models or queries.mongodb/mongodb integration.ext-mongo calls (e.g., MongoClient, MongoCollection) with adapter wrappers.mongodb/mongodb (adapter targets older versions; ensure compatibility with Laravel’s supported PHP/MongoDB stack).jenssegers/laravel-mongodb if both are loaded (adapter may not play well with Laravel’s built-in MongoDB facade).mongodb/mongodb or jenssegers/laravel-mongodb.mongodb/mongodb.ext-mongo queries (e.g., find(), update()) may not map 1:1 to the adapter. Test edge cases like:
ext-mongo cursors vs. modern iterators).eval() in legacy MongoDB).mongodb/mongodb.ext-mongo vs. mongodb/mongodb? Training may be needed for maintenance.jenssegers/laravel-mongodb (with direct mongodb/mongodb integration) be adopted faster? Assess the cost of rewriting legacy logic.ext-mongo? Unit tests for critical queries are essential.ext-mongo; newer versions favor mongodb/mongodb).| Component | Compatible Versions | Notes |
|---|---|---|
| PHP | 7.2–8.2 | Adapter drops support for PHP <7.2. |
| Laravel | 5.4–8.x | Test with target Laravel version. |
mongodb/mongodb |
1.0–1.15 | Adapter targets older versions; check for breaking changes. |
jenssegers/... |
Avoid mixing with adapter | Conflicts likely; choose one approach. |
ext-mongo usage (e.g., MongoClient, MongoCollection, MongoDB).composer require alcaeus/mongo-php-adapter
MongoClient:
// config/database.php
'connections' => [
'mongodb' => [
'driver' => 'mongodb',
'client' => \Alcaeus\MongoDb\MongoClient::class, // Adapter's client
'host' => env('DB_HOST', 'localhost'),
// ... other config
],
]
ext-mongo calls with adapter methods (e.g., MongoClient::selectDB() → adapter’s equivalent).ext-mongo logic to use mongodb/mongodb directly, bypassing the adapter.jenssegers/laravel-mongodb for a more maintainable solution.ext-mongo methods to adapter equivalents (e.g., find() → find() on adapter’s MongoCollection).ext-mongo cursors are lazy; adapter may need explicit iteration).ext-mongo may use loose schema validation. Ensure the adapter enforces equivalent rules or document discrepancies.ext-mongo and mongodb/mongodb have different error classes. Normalize exceptions in application code.ext-mongo behavior.mongodb/mongodb directly, reducing adapter dependency.jenssegers/laravel-mongodb.mongodb/mongodb (adapter may not support newer versions).mongodb/mongodb and PHP versions to avoid compatibility drift.ext-mongo features, performance caveats).ext-mongo and mongodb/mongodb behaviors.ext-mongo documentation.ext-mongo behavior may not translate correctly (e.g., cursor timeouts, bulk write optimizations).mongodb/mongodb or PHP updates breaking adapter compatibility.mongodb/mongodb integration.ext-mongo-specific logic failing silently.ext-mongo vsHow can I help you explore Laravel packages today?