Learn about new features, improvements, and fixes introduced in the following versions of the MongoDB PHP Library:
What's New in 2.1
Important
Breaking Changes
The PHP library v2.1 release introduces the following breaking changes:
Drops support for MongoDB Server 4.0. The minimum supported MongoDB Server version is 4.2.
The PHP library v2.1 release includes the following features, improvements, and fixes:
Adds compatibility with PHP 8.5.
Adds a client bulk write API to perform write operations on multiple databases and collections in the same call. To learn more about this feature, see the Client Bulk Write section of the Bulk Write Operations guide.
What's New in 2.0
Important
Breaking Changes
The PHP library v2.0 release introduces the following breaking changes:
The following methods return
voidinstead of the raw command response:MongoDB\Client:dropDatabase()MongoDB\Collection:drop(),dropIndex(),dropIndexes(),dropSearchIndex(),rename()MongoDB\Database:createCollection(),drop(),dropCollection(),renameCollection()
To learn more about breaking changes in this release, see the Version 2.0 Breaking Changes section in the Upgrade Library Versions guide.
The PHP library v2.0 release includes the following API changes and removals:
Adds the following methods:
MongoDB\Client::getDatabase(): alias forMongoDB\Client::selectDatabase()MongoDB\Client::getCollection(): alias forMongoDB\Client::selectCollection()MongoDB\Database::getCollection(): alias forMongoDB\Database::selectCollection()
The
Client::selectCollection(),Client::selectDatabase(), andDatabase::selectCollection()methods will be deprecated and replaced by these new methods in a future driver release, so consider changing the usages in your application.Modifies the
MongoDB\Database::aggregate()andMongoDB\Collection::aggregate()methods so they can accept aPipelineinstance as the$pipelineparameter. To view examples that use this construction, see the Aggregation Builder section of the Aggregation guide.Replaces
Cursortype hints withCursorInterfacefor better extensibility and compatibility.Removes deprecated fields in GridFS types.
The library does not calculate the
md5field when a file is uploaded to GridFS. If your application requires a file digest, you must implement this process outside GridFS and store the values in metadata.The fields
contentTypeandaliasesare no longer stored in thefilesGridFS collection. If your application requires this information, you must store it in metadata. To learn more about GridFS, see the Store Large Files guide.
Removes the following deprecated options for find operations:
maxScanmodifiersoplogReplaysnapshot
To learn about supported options for find operations, see the
MongoDB\Collection::find()orMongoDB\Collection::findOne()API documentation.Removes the deprecated
IndexInfo::isGeoHaystack()method.Removes the deprecated
autoIndexIdandflagsoptions for theMongoDB\Database::createCollection()method.Drops support for map-reduce functionality by removing the following deprecated methods and types:
MongoDB\Collection::mapReduce()MongoDB\MapReduceResult
You can rewrite map-reduce operations by using aggregation pipeline stages such as
$groupand$merge. To learn more, see Map-Reduce to Aggregation Pipeline in the MongoDB Server manual.Removes the following
Iteratorimplementations:MongoDB\Model\CollectionInfoIteratorMongoDB\Model\DatabaseInfoIteratorMongoDB\Model\IndexInfoIterator
The
MongoDB\Client::listDatabases(),MongoDB\Database::listCollections(), andMongoDB\Collection::listIndexes()methods return a general traversableIteratorinstance that provides the corresponding results.
What's New in 1.21
The PHP library v1.21 release includes the following features, improvements, and fixes:
Introduces the Aggregation Builder, an API to build aggregation pipelines in a more type-safe way. To learn more and view examples, see the Aggregation Builder section of the Aggregation guide.
Adds the following methods:
MongoDB\Client::getDatabase(): alias forMongoDB\Client::selectDatabase()MongoDB\Database::getCollection(): alias forMongoDB\Database::selectCollection()MongoDB\Database::getCollection(): alias forMongoDB\Database::selectCollection()
The
Client::selectCollection(),Client::selectDatabase(), andDatabase::selectCollection()methods will be deprecated and replaced by these new methods in a future driver release, so consider changing the usages in your application.Adds named arguments for the
SearchStage,VectorSearchStage, andSearchMetaStagebuilder classes. This change allows you to write MongoDB Search and MongoDB Vector Search queries in a more type-safe and organized way. To learn more, see the Run a MongoDB Search Query and Run a MongoDB Vector Search Query guides.Deprecates the
flagsoption, used for the deprecated MMAPv1 storage engine. This option will be removed in PHP library v2.0.Adds a sort option to the
MongoDB\Collection::updateOne()andMongoDB\Collection::replaceOne()methods. This change also allows you to set a sort order as an option when performing update and replace operations in a bulk operation.Adds the
builderEncoderoption to the following methods:
For more information about the changes in this version, see the v1.21 release notes on GitHub.
What's New in 1.20
Important
MongoDB Server v3.6 End-of-Life
Support for MongoDB Server v3.6 is removed in this release of the library.
Adds support for MongoDB Server v8.0.
Adds support for Queryable Encryption (QE) range queries. To use this feature, your app must connect to MongoDB Server 8.0 or later. For more information about QE range queries, see Queryable Encryption in the MongoDB Server manual.
When a sharded cluster operation is unsuccessful, the library avoids selecting the same
mongosserver for operation retry attempts if othermongosservers are available.When you create a KMIP data key, you can now specify the
delegatedoption. If this option is set totrue, the KMIP provider performs encryption and decryption of the data key locally, ensuring that the encryption key never leaves the KMIP server.Adds the
typeoption in Search index specifications for theMongoDB\Collection::createIndex()andMongoDB\Collection::createSearchIndexes()methods. This change allows you to create MongoDB Vector Search indexes programmatically. To learn more and view examples, see the MongoDB Search Indexes guide.
For more information about the changes in this version, see the v1.20 release notes on GitHub.
What's New in 1.19
This release of the PHP library contains no significant changes and was added to keep version parity with the PHP extension.
What's New in 1.18
Adds a new GridFS API to make it more convenient to work with files using PHP's existing filesystem functions. The
MongoDB\GridFS\Bucket::registerGlobalStreamWrapperAlias()method may be used to register a global alias for a GridFS bucket. After doing so, files within that bucket can be accessed by using only a file URI (e.g. "gridfs://mybucket/hello.txt"). A demonstration of this API can be found in the gridfs_stream_wrapper.php example script.Adds
MongoDB\Client::addSubscriber()andMongoDB\Client::removeSubscriber()methods to theMongoDB\Clientclass to make it easier to register monitoring classes scoped to the underlyingMongoDB\Driver\Managerobject.
To learn more about this release, see the v1.18 Release Notes on GitHub.
What's New in 1.17
Introduces a new "codec" API for converting BSON to and from PHP objects. More information on this feature may be found in the Codecs tutorial.
Adds
MongoDB\add_logger()andMongoDB\remove_logger()functions to the library. These functions allow applications to register a PSR-3 Logger to receive log messages emitted by the driver. Previously, logs were only available through the extension's mongodb.debugINIsetting.Introduces new
MongoDB\Collectionmethods to create and manage MongoDB Search indexes. MongoDB Search indexes can be queried using the$searchaggregation pipeline stage, which is supported in all versions of the library. To learn more about MongoDB Search indexes and the specifics of the$searchaggregation stage, see the MongoDB Search indexes documentation and $search.Upgrades the
mongodbextension requirement to 1.17.0. Support for PHP 7.2 and 7.3 has been removed and the library now requires PHP 7.4 or newer.
To learn more about this release, see the v1.17 Release Notes on GitHub.