Arrays of MongoIds are sometimes stored as arrays of strings #623

toomuchpete opened this Issue Aug 29, 2012 · 2 comments

3 participants


Lithium MongoDB entities seem incapable of saving an array of MongoIds to existing records. They handle saving to new records just fine, but fail to update properly.

In that paste, Widgets is an empty model. Originally, line 6 was commented out and line 3 was active. That produces the first mongo output. For the second run, line 3 was commented out and line 6 was active.

Union of RAD member

Test from paste:

            // Create New
            // $something = \app\models\Widgets::create();

            // Load Original
            $something = \app\models\Widgets::find('503d149a5b96b8ec33000003');

            $something->save(array('x' => array(new \MongoId(), new \MongoId(), new \MongoId())));

// After create
> db.widgets.findOne();
    "_id" : ObjectId("503d149a5b96b8ec33000003"),
    "x" : [

// After load and save
> db.widgets.findOne();
    "_id" : ObjectId("503d149a5b96b8ec33000003"),
    "x" : [

I actually discovered this recently and have a patch. Just submitted a pull request for it.

The main problem is that when lithium\util\Collection calls ->to('array') on sub-objects, it doesn't pass through the handlers that are used by the MongoDb Exporter that preserves MongoId and MongoDate objects.

@nateabele nateabele added a commit that closed this issue Sep 13, 2012
@nateabele nateabele Ensuring Mongo object arrays don't get stored as strings, fixes #623.…
… Implementing schema null value support, fixes #629.
@nateabele nateabele closed this in 7bc8e25 Sep 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment