When using Mongodb with PHP we have to keep in mind that there are two versions of drivers.
We have the extension mongo
and the extension mongodb
, the second being the latest version.
The driver you will use depends on the version of PHP and Mongodb you are using.
See which to choose according to the tables extracted from the mongodb documentation:
PHP Driver | MongoDB 2.4 | MongoDB 2.6 | MongoDB 3.0 | MongoDB 3.2
-------------------------- |------------- |------------- |------------- |-------------
PHPLIB 1.0 + mongodb-1.1 | X | X | X | X
mongodb-1.1 | X | X | X | X
mongodb-1.0 | X | X | X |
mongo-1.6 | X | X | X |
mongo-1.5 | X | X | |
PHP Driver | PHP 5.3 | PHP 5.4 | PHP 5.5 | PHP 5.6 | PHP 7.0 | HHVM 3.9
-------------|---------|---------|---------|---------|---------|----------
mongodb-1.1 | | X | X | X | X | X
mongodb-1.0 | | X | X | X | | X
mongo-1.6 | X | X | X | X | |
mongo-1.5 | X | X | X | X | |
From a code point of view, the new extension has a greater focus on low-level operations for communication with Mongodb, so much so that it is recommended to use it in conjunction with the Mongodb Library to have an interface similar to the old driver.
I will have to migrate my application to this new driver?
In your case, it depends on the version of PHP and Mongodb you are using.
The latest version of the old driver supports up to Mongodb 3.0 and PHP 5.6. Just remove the new driver and install the old version. You can do that using the PECL.
If you want to use the newer version of Mongodb or PHP 7, then you need to change your code to use library most recent.