PHPackages                             trismegiste/strangelove-bundle - 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. trismegiste/strangelove-bundle

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

trismegiste/strangelove-bundle
==============================

How I Learned to Stop Worrying about ORM and Love MongoDb BSON

3.1.1(10mo ago)286MITPHPPHP &gt;7.4

Since Apr 2Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/Trismegiste/strangelove-bundle)[ Packagist](https://packagist.org/packages/trismegiste/strangelove-bundle)[ RSS](/packages/trismegiste-strangelove-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (9)Versions (21)Used By (0)

Strangelove
===========

[](#strangelove)

[![How I Learned to Stop Worrying about Doctrine and Love MongoDb BSON](https://github.com/Trismegiste/strangelove-bundle/raw/master/docs/strangelove-title.png)](https://github.com/Trismegiste/strangelove-bundle/blob/master/docs/strangelove-title.png)

A symfony bundle for stopping the chase after the mythical object-database, or its fake approximation a.k.a Doctrine.

MongoDb
-------

[](#mongodb)

A almost-zero-config Object Data Mapper for MongoDB. It's a micro database layer with automatic mapping that rely on BSON types. It is intended for **advanced users** of MongoDB who know and understand the growth of a model on a schemaless database.

When I mean "micro", I mean the sum of NCLOC is about one hundred. Therefore it is fast as hell.

Install
-------

[](#install)

### Include the bundle

[](#include-the-bundle)

```
$ composer require trismegiste/strangelove-bundle
```

You'll probably get an error at cache clearing since the config file `strangelove.yaml` does not exist yet.

### Configure the bundle

[](#configure-the-bundle)

Just run the wizard and answer the questions :

```
$ vendor/bin/strangelove-wizard.php
```

### Create a Repository on a collection

[](#create-a-repository-on-a-collection)

Create a subclass of `Trismegiste\Strangelove\MongoDb\DefaultRepository` and extend it with business features.

### Register the service

[](#register-the-service)

To register the repository class MyMovies on the collection 'movies' into the `services.yaml` config file, just add :

```
services:
    # ... some services
    App\Repository\MyMovies:
        $collectionName: movies
```

How
---

[](#how)

Since you have atomicity on one document in MongoDB, you have to store complex tree-ish objects. If you avoid circular references, this ODM stores your object in a comprehensive structure into a MongoDB collection.

Every object has to implement one interface and use one trait :

```
class MyEntity implements \MongoDB\BSON\Persistable {
    use \Trismegiste\Strangelove\MongoDb\PersistableImpl;
}
```

The "top document" or the "root document", meaning the one who owns the primary key (a.k.a the field "\_id" in MongoDB), must implement the interface Root and use the trait RootImpl.

```
class MyDocument implements \Trismegiste\Strangelove\MongoDb\Root {
    use \Trismegiste\Strangelove\MongoDb\RootImpl;
}
```

Repositories
------------

[](#repositories)

There is a default repository against a collection : `DefaultRepository`.

### Loading

[](#loading)

```
$record = $myRepository->load($primaryKey);
```

### Persisting

[](#persisting)

```
$myRepository->save($oneObjectInheritingFromRoot);
$rimaryKey = $oneObjectInheritingFromRoot->getPk();
```

### Searching

[](#searching)

```
$iter = $myRepository->search(['price' => ['$ne' => null]]);
foreach($iter as $record) {
   var_dump($record);
}
```

This class implements the interface Repository. Read the phpdoc about it.

Types
-----

[](#types)

- Don't use DateTime in your model, use BsonDateTime, you have a nice AbstractType for replacing Symfony DateType that converts DateTime into BsonDateTime
- Don't use SplObjectStorage in your model, use BsonObjectStorage
- Don't use SplFixedArray in your model, use BsonFixedArray

Please read the documentation about BSON serialization in MongoDB to know more : [The MongoDB\\BSON\\Persistable interface](https://www.php.net/manual/en/class.mongodb-bson-persistable.php)

Performance
-----------

[](#performance)

A thousand of complex objects that contain about a thousand embedded objects take 2.5 seconds to store on a cheap laptop. And it takes about 1.8 seconds to load and hydrate.

Internals
---------

[](#internals)

This ODM fully relies on BSON API for MongoDB. Your objects can be anything you want : no annotation, no constraint on constructor or extending some mandatory concrete class. Serialization and unserialization are made in the driver written in C, not PHP, that's why it is so fast.

Tests
-----

[](#tests)

This library is full tested with PHPUnit. Simply run :

```
$ vendor/bin/phpunit
```

A full functional test can be found in DefaultRepositoryTest.php.

Iterator
--------

[](#iterator)

Currently, there is one Decorator for an Iterator object : `ClosureDecorator`. It is useful for decorating iterators on cursors created by MongoDB repositories (see above)

Code coverage
-------------

[](#code-coverage)

Code coverage configurations are included in the `phpunit.xml`. Just run :

```
$ phpdbg -qrr vendor/bin/phpunit
```

Html results are stored in ./docs/coverage.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance53

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

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

Recently: every ~49 days

Total

20

Last Release

325d ago

Major Versions

v1.1.1 → 2.0.02022-04-10

2.0.10 → 3.0.12024-12-06

PHP version history (2 changes)v1.0.0PHP &gt;7.3

2.0.8PHP &gt;7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/64cc99ca21a090b2454784670e4ac49db17794d6861078eeceebdbe302365c3f?d=identicon)[trismegiste](/maintainers/trismegiste)

---

Top Contributors

[![Trismegiste](https://avatars.githubusercontent.com/u/1260026?v=4)](https://github.com/Trismegiste "Trismegiste (107 commits)")

---

Tags

bundlemongodbodmserializersymfonyzero-configuration

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/trismegiste-strangelove-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/trismegiste-strangelove-bundle/health.svg)](https://phpackages.com/packages/trismegiste-strangelove-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[a2lix/translation-form-bundle

Translate your doctrine objects easily with some helpers

3376.9M38](/packages/a2lix-translation-form-bundle)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[bartlett/php-compatinfo-db

Reference Database of all functions, constants, classes, interfaces on PHP standard distribution and about 110 extensions

1183.0k1](/packages/bartlett-php-compatinfo-db)

PHPackages © 2026

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