PHPackages                             m1x0n/eventsauce-mongo-message-repository - 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. m1x0n/eventsauce-mongo-message-repository

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

m1x0n/eventsauce-mongo-message-repository
=========================================

MongoDB storage implementation for domain events

v1.1.0(6y ago)94MITPHPPHP ^7.2CI failing

Since Dec 25Pushed 6y ago1 watchersCompare

[ Source](https://github.com/m1x0n/eventsauce-mongo-message-repository)[ Packagist](https://packagist.org/packages/m1x0n/eventsauce-mongo-message-repository)[ RSS](/packages/m1x0n-eventsauce-mongo-message-repository/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (6)Versions (4)Used By (0)

eventsauce-mongo-message-repository [![Build Status](https://camo.githubusercontent.com/c713ac166e36573770053296d3fdba7e223e6946d1c9c7a5b7d107e58ef501a4/68747470733a2f2f7472617669732d63692e6f72672f6d3178306e2f6576656e7473617563652d6d6f6e676f2d6d6573736167652d7265706f7369746f72792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/m1x0n/eventsauce-mongo-message-repository)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#eventsauce-mongo-message-repository-)

MongoDB implementation for [EventSauce](https://eventsauce.io/) message [repository](https://eventsauce.io/docs/advanced/custom-repository/).

### Requirements

[](#requirements)

- php: ^7.2
- ext-mongodb: ^1.6

### Installation

[](#installation)

```
composer require m1x0n/eventsauce-mongo-message-repository

```

### Testing

[](#testing)

```
docker-compose up -d
./vendor/bin/phpunit

```

### Usage

[](#usage)

In order to plug-in this repository:

- MongoDB must be installed on your environment. (See `docker-compose.yaml` for example)
- `ext-mongodb` must be installed for php
- EventSauce aggregate root repository should be configured like this:

```
$mongoDbName = 'mydb';
$eventsCollectionName = 'events';

// Initialize mongo client and select target database
$client = new MongoDB\Client(
    null,
    [
        'username' => 'user',
        'password' => 'secret'
    ]
);

$database = $client->selectDatabase($mongoDbName);

// Configure message repository or see MongoDbMessageRepositoryFactory
$messageRepository = new \EventSauceExtensions\MongoDbMessageRepository(
    $database,
    new \EventSauceExtensions\MongoDbMessageSerializer(
        new \EventSauce\EventSourcing\Serialization\ConstructingMessageSerializer()
    ),
    $eventsCollectionName
);

// MongoDbMessageSerializer also supports upcasting.
// Upcasting is possible by passing upcaster itself as second argument

// This is mostly for example and can be replaced with MessageBus dispatcher like RabbitMQ.
// See eventsauce/rabbitmq-bundle-bindings
$messageDispatcher = new \EventSauce\EventSourcing\SynchronousMessageDispatcher();

// MyAggregateClass must implement
$bulbsAggregateRepository = new \EventSauce\EventSourcing\ConstructingAggregateRootRepository(
    MyAggreateClass::class,
    $messageRepository,
    $messageDispatcher
);
```

The configuration might be slightly simplified by using dependency injection container.

### Event's document structure

[](#events-document-structure)

Events serialization/deserialization was made using following document structure under the hood:

```
{
    "_id": ObjectId("5dfe3322e006a263d256da36"),
    "event_id": "482eacef-04f3-46c1-b88b-79457f67c778",
    "event_type": "foo.bar.baz",
    "aggregate_root_id": "3be51408-3e1e-4970-88e1-faadeb6796f3",
    "aggregate_root_version": 5,
    "time_of_recording": ISODate("2019-12-21T14:58:42.800Z"),
    "headers": {
        "__event_type": "foo.bar.baz",
        "__time_of_recording": "2019-12-21 14:58:42.800066+0000",
        "__aggregate_root_id": "3be51408-3e1e-4970-88e1-faadeb6796f3",
        "__aggregate_root_version": 5,
        "__aggregate_root_id_type": "foo.bar.id"
    },
    "payload": {
        "id": "3be51408-3e1e-4970-88e1-faadeb6796f3"
    }
}

```

The most important information is placed under `headers` and `payload` properties.

### Performance

[](#performance)

The following unique index should be enforced for better performance either for `ConstructingAggregateRootRepository`or `ConstructingAggregateRootRepositoryWithSnapshotting`.

```
Index := unique(aggregate_root_id + aggregate_root_version)

```

It could be done during application bootstrap:

```
$database
    ->selectCollection('events')
    ->createIndex(
    [
        'aggregate_root_id' => 1,
        'aggregate_root_version' => 1,
    ],
    [
        'unique' => true
    ]
);
```

or via mongo shell:

```
db.events.createIndex(
    { aggregate_root_id: 1, aggregate_root_version: 1 },
    { unique: true }
)
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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 ~14 days

Total

3

Last Release

2302d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c110a5e7c621856e30d9059a7fd926ef369af3e200bbce9db6838f4f8e230613?d=identicon)[m1x0n](/maintainers/m1x0n)

---

Top Contributors

[![m1x0n](https://avatars.githubusercontent.com/u/1465680?v=4)](https://github.com/m1x0n "m1x0n (6 commits)")

---

Tags

eventsauceeventsourcingmongodbnosqlstoragestoragenosqlmongodbevent sourcingEventSauce

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/m1x0n-eventsauce-mongo-message-repository/health.svg)

```
[![Health](https://phpackages.com/badges/m1x0n-eventsauce-mongo-message-repository/health.svg)](https://phpackages.com/packages/m1x0n-eventsauce-mongo-message-repository)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[sokil/php-mongo

PHP Object Document Mapper for MongoDB

239161.5k9](/packages/sokil-php-mongo)[leroy-merlin-br/mongolid

Easy, powerful and ultrafast ODM for PHP and MongoDB.

11234.3k4](/packages/leroy-merlin-br-mongolid)[formapro/yadm

The fastest MongoDB object document mapper.

843.3k3](/packages/formapro-yadm)[linkorb/objectstorage

ObjectStorage library for your cloud-based applications

105.4k6](/packages/linkorb-objectstorage)

PHPackages © 2026

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