{"id":13669422,"url":"https://github.com/purekid/mongodm","last_synced_at":"2025-04-27T04:32:52.147Z","repository":{"id":8272557,"uuid":"9727036","full_name":"purekid/mongodm","owner":"purekid","description":"MongoDB ORM that includes support for references,embed and multilevel inheritance.","archived":false,"fork":false,"pushed_at":"2017-04-06T09:07:29.000Z","size":360,"stargazers_count":200,"open_issues_count":19,"forks_count":47,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-10-11T15:49:38.977Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"ExtremeDude2/cmd-tic-tac-toe","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/purekid.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-28T07:36:50.000Z","updated_at":"2024-02-05T22:15:11.000Z","dependencies_parsed_at":"2022-09-17T17:50:22.614Z","dependency_job_id":null,"html_url":"https://github.com/purekid/mongodm","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purekid%2Fmongodm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purekid%2Fmongodm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purekid%2Fmongodm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purekid%2Fmongodm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/purekid","download_url":"https://codeload.github.com/purekid/mongodm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224060283,"owners_count":17248980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T08:01:13.016Z","updated_at":"2024-11-11T06:30:19.430Z","avatar_url":"https://github.com/purekid.png","language":"PHP","funding_links":[],"categories":["PHP","目录","非关系型数据库( NoSQL )"],"sub_categories":["NoSQL"],"readme":"![image](https://gist.github.com/purekid/d3fc0980914209ff436b/raw/6719d0b5346aa45f50a4c19ea3d38e619638d3e1/mongodm.png)\n======= \n\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/a6ae6cc6-fe3a-4cb8-85af-86529a0cb4c2/mini.png)](https://insight.sensiolabs.com/projects/a6ae6cc6-fe3a-4cb8-85af-86529a0cb4c2)\n[![Build Status](https://secure.travis-ci.org/purekid/mongodm.png?branch=master)](http://travis-ci.org/purekid/mongodm)\n[![Latest Stable Version](https://poser.pugx.org/purekid/mongodm/v/stable.png)](https://packagist.org/packages/purekid/mongodm) [![Total Downloads](https://poser.pugx.org/purekid/mongodm/downloads.png)](https://packagist.org/packages/purekid/mongodm) [![License](https://poser.pugx.org/purekid/mongodm/license.png)](https://packagist.org/packages/purekid/mongodm)\n\n- [Introduction](#introduction)\n- [Features](#features)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Setup Database](#setup-database)\n- [Basic Usage - CRUD](#model-crud)\n- [Relationship - Reference](#relationship---reference)\n- [Relationship - Embed](#relationship---embed)\n- [Collection](#collection)\n- [Inheritance](#inheritance)\n- [Other methods](#other-static-methods-in-model)\n- [Model Hooks](#model-hooks)\n- [Special Thanks](#special-thanks-to)\n\n\nIntroduction\n------------\nMongodm is a MongoDB ORM that includes support for references,embed and even multilevel inheritance.\n\nFeatures\n--------\n\n- ORM\n- Simple and flexible\n- Support for embed \n- Support for references (lazy loaded)\n- Support for multilevel inheritance\n- Support for local collection operations\n\nRequirements\n------------\n- PHP 5.3 or greater (Tested for 5.5,5.6,7.0,7.1)\n- Mongodb 1.3 or greater\n- PHP Mongo extension \n\nInstallation\n----------\n\n### 1. Setup in composer.json: \n```json\n\t{\n\t\t\"require\": {\n\t\t    \"purekid/mongodm\": \"dev-master\"\n\t\t}\n\t}\n```\n\n### 2. Install by composer:\n\n\t$ php composer.phar update\n\t\t\n\nSetup Database\n----------\n\nDatabase config file  (By default it locates at /vendor/purekid/mongodm/config.php)\n\n```php\n\treturn array(\n        'default' =\u003e array(\n    \t\t'connection' =\u003e array(\n    \t\t\t'hostnames' =\u003e 'localhost',\n    \t\t\t'database'  =\u003e 'default',\n    // \t\t\t'username'  =\u003e '',\n    // \t\t\t'password'  =\u003e '',\n    \t\t)\n    \t),\n    \t'production' =\u003e array(\n    \t\t'connection' =\u003e array(\n    \t\t\t'hostnames' =\u003e 'localhost',\n    \t\t\t'database'  =\u003e 'production',\n    \t\t\t'options' =\u003e array('replicaSet' =\u003e 'rs0')\n    \t\t)\n    \t)\n    );\n```\n#### Authentication\nAuthentication information is passed in via the options array.  If you do not specifiy authSource, then the PHP Mongo Driver will choose the \"admin\" database.\n\n```\n$config =  array( 'connection' =\u003e array(\n      'hostnames' =\u003e '\u003chost\u003e:\u003cport\u003e',\n      'database'  =\u003e '\u003cdatabasename\u003e',\n      'options'  =\u003e [ \"connectTimeoutMS\" =\u003e 500 , \"username\" =\u003e \"admin\", \"password\" =\u003e \"\u003cpassword\u003e\", \"authSource\" =\u003e \"admin\"] )\n  );\n```\n\n### Setup database in application\n\n1.You can set up configuration using the `MongoDB::setConfigBlock` method.\n\n```php\n\n\\Purekid\\Mongodm\\MongoDB::setConfigBlock('default', array(\n    'connection' =\u003e array(\n        'hostnames' =\u003e 'localhost',\n        'database'  =\u003e 'default',\n        'options'  =\u003e array()\n    )\n));\n\n// \n\\Purekid\\Mongodm\\MongoDB::setConfigBlock('auth', array(\n    'connection' =\u003e array(\n        'hostnames' =\u003e 'localhost',\n        'database'  =\u003e 'authDB',\n        'options'  =\u003e array()\n    )\n));\n\n```\n\n2.Or you can duplicate a config file into your project, then define a global constanct 'MONGODM_CONFIG' with it's location.\n\n```php\n\n//in a global initialization place\n\ndefine('MONGODM_CONFIG',__DIR__.\"/../config/mongodm.php\");\n\n```\n\n### Choose config section with APPLICATION_ENV\n\nWhich config section Mongodm use ? Mongodm choose 'default' section by default.\n\nYou have two ways to specify section :\n\n1.'$config' attribute in Model , you can find this attribute in example below.\n\n2.With environment constanct 'APPLICATION_ENV' ,this constanct can be set by webserver,your code or shell environment.  In this case,you should set $config='default' or don't declare $config in your own model class.\n\n\n### Create a model and enjoy it\n\n```php       \n    \n    use Purekid\\Mongodm\\Model;\n    \n    class User extends Model \n    {\n    \n        static $collection = \"user\";\n        \n        /** use specific config section **/\n        public static $config = 'testing';\n        \n        /** specific definition for attributes, not necessary! **/\n        protected static $attrs = array(\n                \n             // 1 to 1 reference\n            'book_fav' =\u003e array('model'=\u003e'Purekid\\Mongodm\\Test\\Model\\Book','type'=\u003e Model::DATA_TYPE_REFERENCE),\n             // 1 to many references\n            'books' =\u003e array('model'=\u003e'Purekid\\Mongodm\\Test\\Model\\Book','type'=\u003e Model::DATA_TYPE_REFERENCES),\n            // you can define default value for attribute\n            'age' =\u003e array('default'=\u003e16,'type'=\u003e Model::DATA_TYPE_INTEGER),\n            'money' =\u003e array('default'=\u003e20.0,'type'=\u003e Model::DATA_TYPE_DOUBLE),\n            'hobbies' =\u003e array('default'=\u003earray('love'),'type'=\u003e Model::DATA_TYPE_ARRAY),\n            'born_time' =\u003e array('type'=\u003e Model::DATA_TYPE_TIMESTAMP),\n            'family'=\u003earray('type'=\u003e Model::DATA_TYPE_OBJECT),\n            'pet_fav' =\u003e array('model'=\u003e'Purekid\\Mongodm\\Test\\Model\\Pet','type'=\u003e Model::DATA_TYPE_EMBED),\n            'pets' =\u003e array('model'=\u003e'Purekid\\Mongodm\\Test\\Model\\Pet','type'=\u003e Model::DATA_TYPE_EMBEDS),\n                \n        );\n\n        public function setFirstName($name) {\n        \t$name = ucfirst(strtolower($name));\n        \t$this-\u003e__setter('firstName', $name);\n        }\n\n        public function getLastName($name) {\n        \t$name = $this-\u003e__getter('name');\n        \treturn strtoupper($name);\n        }\n    \n    }\n```    \n\n### Types supported for model attributes\n\n```php\n\n    [\n\t'mixed',  // mixed type \n\t'string',     \n\t'reference',  // 1 ： 1 reference\n\t'references', // 1 ： many references\n\t'embed', \n\t'embeds', \n\t'integer',  \n\t'int',  // alias of 'integer'\n\t'double',     // float \n\t'timestamp',  // store as MongoTimestamp in Mongodb\n\t'date',  // store as DateTime\n\t'boolean',    // true or false\n\t'array',    \n\t'object'\n    ];\n\n    const DATA_TYPE_ARRAY      = 'array';\n    \n    const DATA_TYPE_BOOL       = 'bool';\n    const DATA_TYPE_BOOLEAN    = 'boolean';\n\n    const DATA_TYPE_DATE       = 'date';\n\n    const DATA_TYPE_DBL        = 'dbl';\n    const DATA_TYPE_DOUBLE     = 'double';\n    const DATA_TYPE_FLT        = 'flt';\n    const DATA_TYPE_FLOAT      = 'float';\n\n    const DATA_TYPE_EMBED      = 'embed';\n    const DATA_TYPE_EMBEDS     = 'embeds';\n\n    const DATA_TYPE_INT        = 'int';\n    const DATA_TYPE_INTEGER    = 'integer';\n\n    const DATA_TYPE_MIXED      = 'mixed';\n\n    const DATA_TYPE_REFERENCE  = 'reference';\n    const DATA_TYPE_REFERENCES = 'references';\n\n    const DATA_TYPE_STR        = 'str';\n    const DATA_TYPE_STRING     = 'string';\n\n    const DATA_TYPE_TIMESTAMP  = 'timestamp';\n\n    const DATA_TYPE_OBJ        = 'obj';\n    const DATA_TYPE_OBJECT     = 'object';\n    \n```\n\nIf you put a object instance into a Model attribute and this attribute is undefined in $attrs of Model class,the data of attribute will be omitted when Model saving.\n\n```php\n    \n    $object = new \\stdClass();  \n    $object-\u003ename = 'ooobject';\n    \n    $user = new User();\n    $user-\u003ename = 'michael';\n    $user-\u003emyobject = $object;    // this attribute will be omitted when saving to DB \n    $user-\u003esave();\n\n```\n\nModel CRUD\n---------- \n\n### Create \n```php  \n\t$user = new User();\n\t$user-\u003ename = \"Michael\";\n\t$user-\u003eage = 18;\n\t$user-\u003esave();\n``` \nCreate with initial value\n```php  \n\t$user = new User( array('name'=\u003e\"John\") );\n\t$user-\u003eage = 20;\n\t$user-\u003esave();\n```\n\nCreate using set method\n```php\n\t$user-\u003esetLastName('Jones'); // Alias of $user-\u003elastName = 'Jones';\n\t$user-\u003esetFirstName('John'); // Implements setFirstName() method\n```\n\n#### Set and get values\nYou can set/get values via variable `$user-\u003ename = \"John\"` or by method `$user-\u003egetName()`.\n\nSet using variable or method\n```php\n \t// no \"set\" method exists\n\t$user-\u003elastName = 'Jones';\n\t$user-\u003esetLastName('Jones');\n\n\t// \"set\" method exists implements setFirstName()\n\t$user-\u003efirstName = 'jOhn'; // \"John\"\n\t$user-\u003esetFirstName('jOhn'); // \"John\"\n```\n\nGet using variable or method\n```php\n \t// \"get\" method exists implements getLastName()\n\tprint $user-\u003elastName; // \"JONES\"\n\tprint $user-\u003egetLastName(); // \"JONES\"\n\n\t// no \"get\" method\n\tprint $user-\u003efirstName; // \"John\"\n\tprint $user-\u003esetFirstName('John'); // \"John\"\n```\n\n### Update\n```php  \n\t$user-\u003eage = 19;\n```\nUpdate attributes by array\n```php  \n\t$user-\u003eupdate( array('age'=\u003e18,'hobbies'=\u003earray('music','game') ) ); \n\t$user-\u003esave();\n```\nUnset attributes\n```php  \t\n\t$user-\u003eunset('age');\n\t$user-\u003eunset( array('age','hobbies') );\n\t//or\n\tunset($user-\u003eage);\n```\n### Retrieve single record\n```php  \n\t$user = User::one( array('name'=\u003e\"michael\" ) );\n```\t\nretrieve one record by MongoId\n```php  \n\t$id = \"517c850641da6da0ab000004\";\n\t$id = new \\MongoId('517c850641da6da0ab000004'); //another way\n\t$user = User::id( $id );\n```\t\n### Retrieve records\n\nRetrieve records that name is 'Michael' and acount  of owned  books equals 2\n```php  \n\t$params = array( 'name'=\u003e'Michael','books'=\u003earray('$size'=\u003e2) );\n\t$users = User::find($params);     // $users is instance of Collection\n\techo $users-\u003ecount();\n```      \n### Retrieve all records\n```php  \n\t$users = User::all();\n```\t\n### Count records\n```php  \n\t$count = User::count(array('age'=\u003e16));\n```\n### Delete record\n```php  \n\t$user = User::one();\n\t$user-\u003edelete();\t\n```\t\nRelationship - Reference\n---------- \n### Lazyload a 1:1 relationship record\n```php  \n\t$book = new Book();\n\t$book-\u003ename = \"My Love\";\n\t$book-\u003eprice = 15;\n\t$book-\u003esave();\n\n\t// !!!remember you must save book before!!!\n\t$user-\u003ebook_fav = $book;\n\t$user-\u003esave();\n\n\t// now you can do this\n\t$user = User::one( array('name'=\u003e\"michael\" ) );\n\techo $user-\u003ebook_fav-\u003ename;\n```\n### Lazyload 1:many relationship records\n```php  \n\t$user = User::one();\n\t$id = $user-\u003egetId();\n\n\t$book1 = new Book();\n\t$book1-\u003ename = \"book1\";\n\t$book1-\u003esave();\n\t\n\t$book2 = new Book();\n\t$book2-\u003ename = \"book2\";\n\t$book2-\u003esave();\n\n\t$user-\u003ebooks = array($book1,$book2);\n\t//also you can\n\t$user-\u003ebooks = Collection::make(array($book1,$book2));\n\t$user-\u003esave();\n\n\t//somewhere , load these books\n\t$user = User::id($id);\n\t$books = $user-\u003ebooks;      // $books is a instance of Collection\n```\nRelationship - Embed\n---------- \n\n### Single Embed \n```php  \n\t$pet = new Pet();\n\t$pet-\u003ename = \"putty\";\n\n\t$user-\u003epet_fav = $pet;\n\t$user-\u003esave();\n\n\t// now you can do this\n\t$user = User::one( array('name'=\u003e\"michael\" ) );\n\techo $user-\u003epet_fav-\u003ename;\n```\n### Embeds\n```php  \n\t$user = User::one();\n\t$id = $user-\u003egetId();\n\t\n\t$pet_dog = new Pet();\n\t$pet_dog-\u003ename = \"puppy\";\n\t$pet_dog-\u003esave();\n\t\n\t$pet_cat = new Pet();\n\t$pet_cat-\u003ename = \"kitty\";\n\t$pet_cat-\u003esave();\n\n\t$user-\u003epets = array($pet_cat,$pet_dog);\n\t//also you can\n\t$user-\u003epets = Collection::make(array($pet_cat,$pet_dog));\n\t$user-\u003esave();\n\n\t$user = User::id($id);\n\t$pets = $user-\u003epets;     \n```\n###  Collection \n\n$users is instance of Collection\n```php  \n\t$users = User::find(  array( 'name'=\u003e'Michael','books'=\u003earray('$size'=\u003e2) ) );    \n\t$users_other = User::find(  array( 'name'=\u003e'John','books'=\u003earray('$size'=\u003e2) ) );   \n```\t\nSave\n```php\n    $users-\u003esave() ;  // foreach($users as $user) { $user-\u003esave(); }\n```\nDelete\n```php\n    $users-\u003edelete() ;  // foreach($users as $user) { $user-\u003edelete(); }\n```\nCount \n```php  \n\t$users-\u003ecount();  \n\t$users-\u003eisEmpty();\n```\t\nIteration\t\n```php  \n\tforeach($users as $user) { }  \n\t\n\t// OR use Closure \n\t\n\t$users-\u003eeach(function($user){\n\t\n\t})\n```\t\nSort\n```php  \n\t//sort by age desc\n\t$users-\u003esortBy(function($user){\n\t    return $user-\u003eage;\n\t});\n\t\n\t//sort by name asc\n\t$users-\u003esortBy(function($user){\n\t    return $user-\u003ename;\n\t} , true);\n\t\n\t//reverse collection items\n\t$users-\u003ereverse();\n```\nSlice and Take\n```php  \t\n\t$users-\u003eslice(0,1);\n\t$users-\u003etake(2);\n```\t\nMap\n```php  \t\n\t$func = function($user){\n\t\t  \t\tif( $user-\u003eage \u003e= 18 ){\n\t\t    \t\t$user-\u003eis_adult = true;\n\t        \t}\n\t            return $user;\n\t\t\t};\n\t\n\t$users-\u003emap($func)-\u003esave();   \n\t\n```\t\nFilter \n```php  \n\t$func = function($user){\n\t        \tif( $user-\u003eage \u003e= 18 ){\n\t    \t\t\treturn true;\n\t    \t\t}\n\t\t\t}\n\n\t$adults = $users-\u003efilter($func); // $adults is a new collection\n```\nDetermine a record exists in the collection by object instance\t\n```php  \t\n\t$john = User::one(array(\"name\"=\u003e\"John\"));\n\t\n\t$users-\u003ehas($john) \n```\nDetermine a record exists in the collection by numeric index\t\n```php  \n\t$users-\u003ehas(0) \n```\t\nDetermine a record exists in the collection by MongoID\t\n```php  \n\t$users-\u003ehas('518c6a242d12d3db0c000007') \n```\nGet a record by numeric index\n```php  \n\t$users-\u003eget(0) \n```\nGet a record by MongoID \n```php  \n\t$users-\u003eget('518c6a242d12d3db0c000007') \n```\nRemove a record by numeric index\n```php  \n\t$users-\u003eremove(0)  \n```\nRemove a record  by MongoID\n```php  \n\t$users-\u003eremove('518c6a242d12d3db0c000007') \n```\t\nAdd a single record to collection\n```php  \n\t$bob = new User( array(\"name\"=\u003e\"Bob\"));\n\t$bob-\u003esave();\n\t$users-\u003eadd($bob);\n```\t\nAdd records to collection\n```php  \t\n\t$bob = new User( array(\"name\"=\u003e\"Bob\"));\n\t$bob-\u003esave();\n\t$lisa = new User( array(\"name\"=\u003e\"Lisa\"));\n\t$lisa-\u003esave();\n\t\n\t$users-\u003eadd( array($bob,$lisa) ); \n```\t\nMerge two collection \n```php  \t\n\t$users-\u003eadd($users_other);  // the collection $users_other appends to end of $users \n```\nExport data to a array\n```php  \n\t$users-\u003etoArray();\n```\t\nInheritance\n----------\n\t\n### Define multilevel inheritable models:\n```php  \n\tuse Purekid\\Mongodm\\Model;\n\tnamespace Demo;\n\t\n\tclass Human extends Model{\n\t\n\t\tstatic $collection = \"human\";\n\t\t\n\t\tprotected static $attrs = array(\n\t\t\t'name' =\u003e array('default'=\u003e'anonym','type'=\u003e'string'),\n\t\t\t'age' =\u003e array('type'=\u003e'integer'),\n\t\t\t'gender' =\u003e array('type'=\u003e'string'),\n\t\t\t'dad' =\u003e  array('type'=\u003e'reference','model'=\u003e'Demo\\Human'),\n\t\t\t'mum' =\u003e  array('type'=\u003e'reference','model'=\u003e'Demo\\Human'),\n\t\t\t'friends' =\u003e array('type'=\u003e'references','model'=\u003e'Demo\\Human'),\n\t\t)\n\t\n\t}\n\n\tclass Student extends Human{\n\t\n\t\tprotected static $attrs = array(\n\t\t\t'grade' =\u003e array('type'=\u003e'string'),\n\t\t\t'classmates' =\u003e array('type'=\u003e'references','model'=\u003e'Demo\\Student'),\n\t\t)\n\t\t\n\t}\n```\t\n### Use:\n```php  \n\t$bob = new Student( array('name'=\u003e'Bob','age'=\u003e 17 ,'gender'=\u003e'male' ) );\n\t$bob-\u003esave();\n\t\n\t$john = new Student( array('name'=\u003e'John','age'=\u003e 16 ,'gender'=\u003e'male' ) );\n\t$john-\u003esave();\n\t\n\t$lily = new Student( array('name'=\u003e'Lily','age'=\u003e 16 ,'gender'=\u003e'female' ) );\n\t$lily-\u003esave();\n\t\n\t$lisa = new Human( array('name'=\u003e'Lisa','age'=\u003e41 ,'gender'=\u003e'female' ) );\n\t$lisa-\u003esave();\n\t\n\t$david = new Human( array('name'=\u003e'David','age'=\u003e42 ,'gender'=\u003e'male') );\n\t$david-\u003esave();\n\t\n\t$bob-\u003edad = $david;\n\t$bob-\u003emum = $lisa;\n\t$bob-\u003eclassmates = array( $john, $lily );\n\t$bob-\u003esave();\n```\t\n### Retrieve and check value:\n```php  \n\t$bob = Student::one( array(\"name\"=\u003e\"Bob\") );\n\t\n\techo $bob-\u003edad-\u003ename;    // David\n\t\n\t$classmates = $bob-\u003eclassmates;\n\t\n\techo $classmates-\u003ecount(); // 2\n    \n\tvar_dump($classmates-\u003eget(0)); // john\t\n```\t\n\n### Retrieve subclass\n\nRetrieve all Human records , queries without '_type' because of it's a toplevel class.\n```php  \t\n    $humans = Human::all();\n``` \nRetrieve all Student records , queries with  { \"_type\":\"Student\" } because of it's a subclass.\n```php  \n    $students = Student::all();\n```\n\n### Retrieve subclass _without_ `_type`\n\nTo retrieve a record without the `_type` criteria (i.e. `{ \"_type\":\"Student\" }`) set:\n\n```php\nclass Student extends \\Purekid\\Mongodm\\Model\n{\n    protected static $useType = false;\n\n    protected static $collection = 'Student';\n}\n```\n\n_Make sure to set a collection otherwise you will get results with every `_type`._\n\nOther static methods in Model\n----------\n```php\n\tUser::drop() // Drop collection \n\tUser::ensureIndex()  // Add index for collection\n```\nModel Hooks\n----------\nThe following hooks are available:\n\n##### __init()\n\nExecuted after the constructor has finished\n\n##### __preInsert()\n\nExecuted before saving a new record\n\n##### __postInsert()\n\nExecuted after saving a new record\n\n##### __preUpdate()\n\nExecuted before saving an existing record\n\n##### __postUpdate()\n\nExecuted after saving an existing record\n\n##### __preSave()\n\nExecuted before saving a record\n\n##### __postSave()\n\nExecuted after saving a record\n\n##### __preDelete()\n\nExecuted before deleting a record\n\n##### __postDelete()\n\nExecuted after deleting a record\n\nSpecial thanks to\n-----------------\n\n[mikelbring](https://github.com/mikelbring)\n[Paul Hrimiuc](https://github.com/hpaul/)\n\n\n\t\n\t\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurekid%2Fmongodm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpurekid%2Fmongodm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurekid%2Fmongodm/lists"}