PHPackages                             madewithlove/broadway-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. madewithlove/broadway-mongodb

Abandoned → [broadway/event-store-mongodb](/?search=broadway%2Fevent-store-mongodb)ArchivedLibrary[Database &amp; ORM](/categories/database)

madewithlove/broadway-mongodb
=============================

A mongodb driver for Broadway

0.2.0(10y ago)1451MITPHPPHP &gt;=5.5.9

Since Apr 13Pushed 10y ago2 watchersCompare

[ Source](https://github.com/madewithlove/broadway-mongodb)[ Packagist](https://packagist.org/packages/madewithlove/broadway-mongodb)[ RSS](/packages/madewithlove-broadway-mongodb/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)Dependencies (7)Versions (3)Used By (0)

madewithlove/broadway-mongodb
=============================

[](#madewithlovebroadway-mongodb)

[![Build Status](https://camo.githubusercontent.com/c3b521d969e86adb0c387b38ec0489769b362eab73b8ade427736bb3b9856086/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f6d616465776974686c6f76652f62726f61647761792d6d6f6e676f64622e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/madewithlove/broadway-mongodb)[![Latest Stable Version](https://camo.githubusercontent.com/b0f76c6000756c43be4ae96035c59b5517a5bcb2d1e59a5fb507510097d1a6c6/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d616465776974686c6f76652f62726f61647761792d6d6f6e676f64622e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/madewithlove/broadway-mongodb)[![Total Downloads](https://camo.githubusercontent.com/5593db5a2a4cefd9ad06ed1cfbda74986597f6b14b11347523cdd11e6f429525/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d616465776974686c6f76652f62726f61647761792d6d6f6e676f64622e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/madewithlove/broadway-mongodb)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/b7a13020ac4a256b45be5cdf455065b5f7f7ffc3c58fe1a607efc07eae3fe28a/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d616465776974686c6f76652f62726f61647761792d6d6f6e676f64622e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/madewithlove/broadway-mongodb/)[![Code Coverage](https://camo.githubusercontent.com/6cc1ee9744179ae5acb4c3121077d5017a5617321a255869777482d32e54d514/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6d616465776974686c6f76652f62726f61647761792d6d6f6e676f64622e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/madewithlove/broadway-mongodb/)

A [MongoDB](https://www.mongodb.org/) driver for [Broadway](https://github.com/qandidate-labs/broadway) based on [`mongodb/mongodb`](https://github.com/mongodb/mongo-php-library).

Goals
-----

[](#goals)

Install
-------

[](#install)

This package has the same requirements as [`mongodb/mongodb`](https://github.com/mongodb/mongo-php-library).

```
$ pecl install mongodb
$ echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
```

Via Composer

```
$ composer require madewithlove/broadway-mongodb
```

Usage
-----

[](#usage)

### `MongoDBClientFactory`

[](#mongodbclientfactory)

This package ships with a factory to build a `MongoDB\Client`.

#### Using default values

[](#using-default-values)

```
$factory = new MongoDBClientFactory();
$client = $factory->create(['database' => 'foobar']);
```

#### Creating a client for a specific host and port

[](#creating-a-client-for-a-specific-host-and-port)

```
$factory = new MongoDBClientFactory();
$client = $factory->create([
     'database' => 'foobar',
     'host' => 'my_host',
     'port' => 3000,
]);

// Or alternatively

$client = $factory->create([
     'database' => 'foobar',
     'host' => 'my_host:3000',
]);
```

#### Creating a client for multiple hosts

[](#creating-a-client-for-multiple-hosts)

The `hosts` option can also be an array for multiple hosts

```
$factory = new MongoDBClientFactory();
$client = $factory->create([
     'database' => 'foobar',
     'host' => ['my_host_1', 'my_host_2'],
]);
```

#### Creating a client for with username and password

[](#creating-a-client-for-with-username-and-password)

If you have to authenticate to your MongoDB database you can pass the username and password

```
$factory = new MongoDBClientFactory();
$client = $factory->create([
     'database' => 'foobar',
     'username' => 'foo',
     'password' => 'bar',
]);
```

#### Creating a client using a dsn string

[](#creating-a-client-using-a-dsn-string)

Alternatively you can pass a dsn string and it will be used to connect

```
$factory = new MongoDBClientFactory();
$client = $factory->create([
     'dsn' => 'mongodb://foo:200/foo',
]);
```

### `ReadModel`

[](#readmodel)

This package ships with a basic `MongoDBRepository` class you can either use directly or extend to build your own repositories.

The easiest way to create a repository for your model is by using the `ReadModel\Factory`:

```
$mongDBClientFactory = new MongoDBClientFactory();
$client = $factory->create(['database' => 'testing']);

$factory = new ReadModel\Factory(
   new SimpleInterfaceSerializer(),
   $client->selectDatabase('testing')
);

// 'my_projection' is the collection that will be used.
$repository = $factory->create('my_projector');

// If you have a custom read model repository you can use the factory to create your own instances:
$repository = $factory->create('my_projector', MyReadModelRepository::class);
```

Testing
-------

[](#testing)

```
$ composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~8 days

Total

2

Last Release

3720d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/041cdc8fc831716b7f56c3ddf84169ea1d97ca91e9ea90b42be88d73c404ff8a?d=identicon)[bramdevries](/maintainers/bramdevries)

---

Top Contributors

[![bramdevries](https://avatars.githubusercontent.com/u/1002245?v=4)](https://github.com/bramdevries "bramdevries (19 commits)")

---

Tags

event sourcingcqrsbroadwayprojector

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M88](/packages/mongodb-laravel-mongodb)[patchlevel/event-sourcing

A lightweight but also all-inclusive event sourcing library with a focus on developer experience

202332.6k12](/packages/patchlevel-event-sourcing)[nwidart/laravel-broadway

A Laravel adapter for the Broadway ES/CQRS package.

12315.0k](/packages/nwidart-laravel-broadway)[broadway/broadway-bundle

Symfony bundle for broadway/broadway.

67864.7k7](/packages/broadway-broadway-bundle)

PHPackages © 2026

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