mongodb/mongodb
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
jean85/pretty-package-versions | 2.0.6 | - | MIT | prod | |
psr/log | 3.0.0 | 6.77 kB | MIT | prod | |
symfony/polyfill-php80 | v1.29.0 | - | MIT | prod | |
symfony/polyfill-php81 | v1.29.0 | 4.96 kB | MIT | prod |
The MongoDB PHP Library, known as mongodb/mongodb, is a high-level abstraction layer over the lower-level PHP driver for MongoDB (mongodb
extension). It is designed to provide developers with a complete and user-friendly API similar to other MongoDB drivers. The extension by itself provides limited functionalities for executing commands, queries, and write operations. In contrast, this library encompasses abstractions for client, database, and collection objects, in addition to methods for CRUD operations and daily commands such as index and collection management. If you are developing an application with MongoDB, it would be more beneficial to utilize this library or another high-level abstraction instead of solely depending on the extension.
Using the mongodb/mongodb library is straightforward with Composer. You need to run the following command in your project root:
$ composer require mongodb/mongodb
Also, the library requires the mongodb
extension to be installed:
$ pecl install mongodb
$ echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
A typical usage might look like this:
<?php
require 'vendor/autoload.php'; // include Composer's autoloader
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->demo->beers;
$result = $collection->insertOne( [ 'name' => 'Hinterland', 'brewery' => 'BrewDog' ] );
echo "Inserted with Object ID '{$result->getInsertedId()}'";
Here, MongoDB\Client
is your gateway to the driver's functionality. You specify the server's location upon instantiation. Then, you can select your database and collection and perform operations like insertOne
.
The official documentation for the mongodb/mongodb library can be accessed at the following URLs:
Comprehensive information on installation, usage examples, and the library architecture can be found within these resources.