12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- Title: Indexing
- Author: Dariusz Górecki <darek.krk@gmail.com>
- ---
- Now you can define indexes for yours collections in easy way!
- Suite will check for existing of indexes only once, at the first class use, (per script-calls)
- if it not find any of declared indexes it will create them
- Only thing you need is to define the `indexes()` method in yours model class, see the example:
- ~~~
- [php]
- class Client extends EMongoDocument
- {
- // ....
- public function indexes()
- {
- return array(
- // index name is not important, you may write whatever you want, just must be unique
- 'index1_name'=>array(
- // key array holds list of fields for index
- // you may define multiple keys for index and multikey indexes
- // each key must have a sorting direction SORT_ASC or SORT_DESC
- 'key'=>array(
- 'field_name'=>EMongoCriteria::SORT_ASC
- 'field_name.embeded_field'=>EMongoCriteria::SORT_DESC
- ),
- // unique, if indexed field must be unique, define a unique key
- 'unique'=>true,
- ),
- );
- }
- // ....
- }
- ~~~
- If you whant to disable index existing checking on every page load,
- because of perfomance reasons (recomended for production)
- put `$this->ensureIndexes = false;` into yours `init()` method in model class.
- ~~~
- [php]
- class Client extends EMongoDocument
- {
- // ....
- public function init()
- {
- $this->ensureIndexes = false;
- }
- // ....
- }
- ~~~
|