PHPackages                             phpdot/mongodb - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. phpdot/mongodb

ActiveLibrary[Database &amp; ORM](/categories/database)

phpdot/mongodb
==============

Resilient MongoDB client with fluent CRUD builders, Document object, exception translation, and query logging.

v0.1.1(1mo ago)00MITPHPPHP &gt;=8.5

Since Jul 18Pushed 1mo agoCompare

[ Source](https://github.com/phpdot/mongodb)[ Packagist](https://packagist.org/packages/phpdot/mongodb)[ RSS](/packages/phpdot-mongodb/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (26)Versions (6)Used By (0)

phpdot/mongodb
==============

[](#phpdotmongodb)

A resilient MongoDB client built on the official [`mongodb/mongodb`](https://www.mongodb.com/docs/php-library/current/)library and `ext-mongodb`. It adds fluent CRUD builders, a `Document` object over raw BSON, a typed exception hierarchy translated from driver errors, optional query logging, and a connector so [phpdot/pool](https://github.com/phpdot/pool) can hold and recycle connections.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Architecture](#architecture)
- [Testing](#testing)
- [License](#license)

Requirements
------------

[](#requirements)

RequirementConstraintPHP`>= 8.5``ext-mongodb``^2.1``mongodb/mongodb``^2.1``phpdot/contracts``^0.1``phpdot/container` is a dev-only suggestion — the `#[Config('mongodb')]` attribute on `MongoConfig` is inert until a phpdot application reflects it.

Installation
------------

[](#installation)

```
composer require phpdot/mongodb
```

Usage
-----

[](#usage)

### Connecting and CRUD

[](#connecting-and-crud)

```
use PHPdot\MongoDB\MongoConnection;
use PHPdot\MongoDB\Config\MongoConfig;
use PHPdot\MongoDB\Database\Database;

$connection = new MongoConnection(new MongoConfig(
    hosts: 'localhost',
    database: 'myapp',
));
$connection->connect();

$users = (new Database($connection))->collection('users');

$users->insertOne(['name' => 'Omar', 'email' => 'omar@example.com']);

$user = $users->findOne(['email' => 'omar@example.com']);
echo $user->name; // 'Omar' — a Document with field access
```

### Fluent queries

[](#fluent-queries)

Find, update, and delete each have a fluent builder:

```
$active = $users->find()
    ->filter(['status' => 'active'])
    ->sort(['created_at' => -1])
    ->limit(10)
    ->execute();

foreach ($active as $doc) {
    echo $doc->name;
}

$users->update()
    ->filter(['status' => 'pending'])
    ->set(['status' => 'active'])
    ->execute();

$users->delete()->filter(['status' => 'banned'])->execute();
```

### Documents

[](#documents)

`findOne()` and cursors yield `Document` objects — field access, dot-path reads, type conversions, and `ArrayAccess`/`JsonSerializable`, over the raw BSON the driver returns.

### Resilience and exceptions

[](#resilience-and-exceptions)

`connect()` retries with exponential backoff up to `maxRetries`. Driver errors are translated into a typed hierarchy — `AuthenticationException`, `ConnectionException`, `TimeoutException`, `DuplicateKeyException`, `BulkWriteException`, `ValidationException`, and more — all extending the package's `MongoException`.

### Pooling

[](#pooling)

`MongoConnector` adapts a `MongoConnection` to `phpdot/pool`'s `ConnectorInterface`, so a pool can build, health-check, and recycle connections — one connection per coroutine.

Architecture
------------

[](#architecture)

`MongoConnection` owns a `MongoDB\Client` and drives its lifecycle (backoff connect, ping, exception translation). `Database` and `Collection` expose the fluent API; the query builders compile to the options the underlying library accepts. `MongoConnector` bridges to `phpdot/pool`.

 ```
graph TD
    APP["Application / phpdot/pool"]
    CONNECTOR["MongoConnectorContracts Pool ConnectorInterface"]
    CONN["MongoConnectionlifecycle, backoff reconnect,exception translation, query log"]
    DB["Database → CollectionFind / Update / Delete builders,Document over BSON"]
    CONFIG["MongoConfighosts, topology, timeouts(#[Config('mongodb')])"]
    LIB["mongodb/mongodb + ext-mongodbMongoDB\\Client, MongoDB\\Driver\\*"]

    APP --> CONNECTOR
    CONNECTOR --> CONN
    CONFIG --> CONN
    CONN --> DB
    DB --> LIB
    CONN --> LIB
```

      Loading Testing
-------

[](#testing)

```
composer install
composer test        # PHPUnit
composer analyse     # PHPStan, level max + strict rules
composer cs-check    # PHP-CS-Fixer
composer check       # All three
```

The unit suite runs with no server. The integration suite connects to a MongoDB at `127.0.0.1:27017`and **skips automatically when none is reachable**.

License
-------

[](#license)

MIT.

**This repository is a read-only mirror**, generated by CI from [phpdot/monorepo](https://github.com/phpdot/monorepo). [Pull requests](https://github.com/phpdot/monorepo/pulls)and [issues](https://github.com/phpdot/monorepo/issues) belong in the monorepo.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance94

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~26 days

Total

5

Last Release

31d ago

Major Versions

v1.0.0 → v2.0.02026-05-03

PHP version history (3 changes)v1.0.0PHP &gt;=8.3

v2.0.1PHP &gt;=8.4

v0.1.0PHP &gt;=8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/62e82421bda4b5d6ba9a47ba6d88caca060dcd0d1a2862f351f3a97657385db0?d=identicon)[phpdot](/maintainers/phpdot)

---

Top Contributors

[![phpdot](https://avatars.githubusercontent.com/u/252500?v=4)](https://github.com/phpdot "phpdot (5 commits)")[![o3AM](https://avatars.githubusercontent.com/u/252500?v=4)](https://github.com/o3AM "o3AM (2 commits)")

---

Tags

databasefluentnosqlmongodbcruddocument

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpdot-mongodb/health.svg)

```
[![Health](https://phpackages.com/badges/phpdot-mongodb/health.svg)](https://phpackages.com/packages/phpdot-mongodb)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.9M110](/packages/mongodb-laravel-mongodb)[leroy-merlin-br/mongolid

Easy, powerful and ultrafast ODM for PHP and MongoDB.

11336.2k9](/packages/leroy-merlin-br-mongolid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
