andydune / mongo-odm
AObject Document mapper for mongoDB with no proxies, special configuration.
v1.3.3
2018-05-17 06:58 UTC
Requires
- php: >=7.1
- andydune/array-container: >=1.6
- andydune/conditional-execution: ^1
- andydune/datetime: ^2
- mongodb/mongodb: ^1.1
Requires (Dev)
- mongodb/mongodb: ^1.1
- phpunit/phpunit: ^5.7.15 || ^6.0.8
README
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);