:link: Adapter to provide ext-mongo interface on top of mongo-php-library
The Mongo PHP Adapter is a userland library designed to act as an adapter between applications relying on ext-mongo and the new driver (
It provides the API of ext-mongo built on top of mongo-php-library, thus being compatible with PHP 7.
This library aims to provide a compatibility layer for applications that rely on libraries using ext-mongo, e.g. Doctrine MongoDB ODM, but want to migrate to PHP 7 on which
ext-mongowill not run.
You should not be using this library if you do not rely on a library using
ext-mongo. If you are starting a new project, please check out mongodb/mongodb.
This library requires you to have the
mongodbextension installed, and it conflicts with the legacy
The preferred method of installing this library is with Composer by running the following from your project root:
$ composer config "platform.ext-mongo" "1.6.16" && composer require alcaeus/mongo-php-adapter
The above command first marks the
mongoextension as installed, then requires this adapter. This is to work around a bug in composer, see composer/composer#5030.
Some methods may not throw exceptions with the same exception messages as their counterparts in
ext-mongo. Do not rely on exception messages being the same.
Methods that return a result array containing a
connectionIdfield will always return
0as connection ID.
All errors and warnings triggered by
ext-mongoare triggered as
trigger_errordoesn't accept the
E_USERcodes. If you rely on these error codes in your error handling routines, please update your code accordingly.
Serialization of any Mongo* objects (e.g. MongoGridFSFile, MongoCursor, etc.) will not work properly. The objects can be serialized but are not usable after unserializing them.
$cmdcollection cannot be used due to an issue in the underlying driver. To run commands, use the command method instead of querying the virtual
serverkeys once the cursor has started iterating. The
numReturnedfield will always show the same value as the
serverfield is lacking authentication information.
numReturnedfields always return 0 for compatibility to MongoCursor. The
firstBatchNumReturnedfields will contain the same value, which is the internal position of the iterator.
If you are working on patches to this driver, you can run the unit tests by following these steps from the root of the repo directory:
$ composer install $ vendor/phpunit/phpunit/phpunit --verbose
It assumes that the the
localhostis running a mongod server. Here is a sample command to start mongod for these tests:
$ mongod --smallfiles --fork --logpath /var/log/mongod.log --setParameter enableTestCommands=1
The tests also assume PHP 5.6+ and the
ext-mongodbextension being available.