andydune/mongo-odm

AObject Document mapper for mongoDB with no proxies, special configuration.

v1.3.3 2018-05-17 06:58 UTC

This package is auto-updated.

Last update: 2024-10-18 19:33:00 UTC


README

Build Status Software License Packagist Version Total Downloads

Object Document mapper for mongoDB with no proxies, special configuration.

Installation

Installation using composer:

composer require andydune/mongo-odm

Or if composer was not installed globally:

php composer.phar require andydune/mongo-odm

Or edit your composer.json:

"require" : {
     "andydune/mongo-odm": "^1"
}

And execute command:

php composer.phar update

Control types

 $mongo = new \MongoDB\Client();
        $collection = $mongo->selectDatabase('test')->selectCollection('test_odm');
        $collection->deleteMany([]);

        $odmClass = new class($collection) extends DocumentAbstract
        {
            protected function describe()
            {
                $this->fieldsMap['number'] = 'integer';
                $this->fieldsMap['code'] = 'string';
                $this->fieldsMap['birthday'] = 'datetime';
            }
        };

        $time = time();
        $odmClass->number = '12';
        $odmClass->code = '125';
        $odmClass->birthday = date('Y-m-d H:i:s', $time);
        $odmClass->save();

        $res = $collection->findOne(['number' => 12]);
        $this->assertTrue((bool)$res);
        $res = $collection->findOne(['number' => '12']);
        $this->assertFalse((bool)$res);