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

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

mongodb/transistor
==================

Simple MongoDB Object&lt;-&gt;Document Mapper

0.1.0(11y ago)291573[3 issues](https://github.com/bjori/mongo-php-transistor/issues)BSD 2-ClausePHP

Since Apr 22Pushed 10y ago4 watchersCompare

[ Source](https://github.com/bjori/mongo-php-transistor)[ Packagist](https://packagist.org/packages/mongodb/transistor)[ Docs](https://github.com/bjori/mongo-php-transistor)[ RSS](/packages/mongodb-transistor/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (2)Used By (0)

mongo-php-transistor
====================

[](#mongo-php-transistor)

[![Build Status](https://camo.githubusercontent.com/7b22410b924de19685cdc88352c2ae6ced5363bcefc9106e08b0165b46335ebc/68747470733a2f2f6170692e7472617669732d63692e6f72672f626a6f72692f6d6f6e676f2d7068702d7472616e736973746f722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/bjori/mongo-php-transistor)

The new [PHP Driver for MongoDB](http://github.com/mongodb/mongo-php-driver)provides a [MongoDB\\BSON\\Persistable](http://php.net/mongodb_bson_persistable) interface which declares two methods to be called when storing the object, and the other when re-constructing it.

This `transistor` trait adds example implementation of the two methods and introduces lightweight change tracking. This allows the object to be seamlessly updated as well.

Example classes
---------------

[](#example-classes)

```

```

See [Person.php](tests/utils/classes/Person.php) and [Address.php](tests/utils/classes/Address.php) for the full implementation of these example classes -- although this is really it. No annotations or anything. `implements MongoDB\BSON\Persistable` and `use MongoDB\Transistor` is the magic.

Simple usage
------------

[](#simple-usage)

```

```

The above example will output something similar to

```
object(Person)#8 (7) {
  ["_id"]=>
  object(MongoDB\BSON\ObjectID)#4 (1) {
    ["oid"]=>
    string(24) "553586e2bd21b971774b7da1"
  }
  ["username"]=>
  string(5) "bjori"
  ["email"]=>
  string(13) "bjori@php.net"
  ["name"]=>
  string(16) "Hannes Magnusson"
  ["addresses"]=>
  array(0) {
  }
  ["_lastModified"]=>
  NULL
  ["_created"]=>
  object(MongoDB\BSON\UTCDatetime)#7 (0) {
  }
}

```

Updating the object
-------------------

[](#updating-the-object)

```

```

The above example will output something similar to

```
object(Person)#9 (7) {
  ["_id"]=>
  object(MongoDB\BSON\ObjectID)#4 (1) {
    ["oid"]=>
    string(24) "553586e2bd21b971774b7da1"
  }
  ["username"]=>
  string(5) "bjori"
  ["email"]=>
  string(13) "bjori@php.net"
  ["name"]=>
  string(16) "Dr. Hannes Magnusson"
  ["addresses"]=>
  array(0) {
  }
  ["_lastModified"]=>
  NULL
  ["_created"]=>
  object(MongoDB\BSON\UTCDatetime)#7 (0) {
  }
}

```

Adding embedded objects
-----------------------

[](#adding-embedded-objects)

```

```

The above example will output something similar to

```
object(Person)#10 (7) {
  ["_id"]=>
  object(MongoDB\BSON\ObjectID)#4 (1) {
    ["oid"]=>
    string(24) "553586e2bd21b971774b7da1"
  }
  ["username"]=>
  string(5) "bjori"
  ["email"]=>
  string(13) "bjori@php.net"
  ["name"]=>
  string(16) "Dr. Hannes Magnusson"
  ["addresses"]=>
  array(1) {
    [0]=>
    object(Address)#%d (%d) {
      ["_id"]=>
      object(MongoDB\BSON\ObjectID)#%d (%d) {
        ["oid"]=>
        string(24) "%s"
      }
      ["streetAddress"]=>
      string(11) "Manabraut 4"
      ["city"]=>
      string(9) "Kopavogur"
      ["postalCode"]=>
      int(200)
      ["_created"]=>
      object(MongoDB\BSON\UTCDatetime)#%d (0) {
      }
    }
  }
  ["_lastModified"]=>
  NULL
  ["_created"]=>
  object(MongoDB\BSON\UTCDatetime)#7 (0) {
  }
}

```

### Helpers

[](#helpers)

The [insert()](tests/utils/tools.inc#L4-L13), [update()](tests/utils/tools.inc#L15-L26)and [findOne()](tests/utils/tools.inc#L28-L41) helpers in the example above don't do anything other then wrap their respective methods on the [MongoDB\\Driver\\Manager](http://php.net/MongoDB_Driver_Manager) and setting the [TypeMap](http://php.net/MongoDB_Driver_Cursor.settypemap), and are only there to reduce error checking needed in the examples.

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

[](#performance)

Since the actual object (un-)serialization is done by the extension itself there is nothing for PHP to do -- the trait itself is under 200 lines of dead simple code.

I'm sure there are dragons, so use with care.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 79.2% 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

Unknown

Total

1

Last Release

4090d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/288a66e97715e2b9764c457ff661f30efb6da81595dcc2b31a5d6fffd4fde28a?d=identicon)[bjori](/maintainers/bjori)

---

Top Contributors

[![bjori](https://avatars.githubusercontent.com/u/72407?v=4)](https://github.com/bjori "bjori (38 commits)")[![renanbr](https://avatars.githubusercontent.com/u/350222?v=4)](https://github.com/renanbr "renanbr (10 commits)")

---

Tags

persistencedatabaseormodmmongodbdriver

### Embed Badge

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

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

###  Alternatives

[mongodb/mongodb

MongoDB driver library

1.6k67.9M625](/packages/mongodb-mongodb)[mongodb/mongodb-extension

MongoDB driver extension

91941.7k](/packages/mongodb-mongodb-extension)[doctrine/phpcr-bundle

Symfony DoctrinePHPCRBundle

1602.7M42](/packages/doctrine-phpcr-bundle)[denchikby/phalcon-mongodb-odm

Phalcon MongoDB ODM

4213.2k](/packages/denchikby-phalcon-mongodb-odm)

PHPackages © 2026

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