- 6. The Advanced Stuff
6.1. Indexing - 6. The Advanced Stuff
« Previous - 6.2. Primary Keys
Next »
6.1. Indexing
Author | Dariusz Górecki |
---|
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:
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.
class Client extends EMongoDocument { // .... public function init() { $this->ensureIndexes = false; } // .... }
- 6.1. Indexing
6. The Advanced Stuff - « Previous
6. The Advanced Stuff - Next »
6.2. Primary Keys