2017 © Pedro Peláez
 

lithium-library li3_ensureindex

image

knodes/li3_ensureindex

  • Wednesday, October 16, 2013
  • by leek
  • Repository
  • 3 Watchers
  • 3 Stars
  • 717 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

li3_ensureindex

li3_ensureindex allows you to define MongoDB indexes within your models, and ensure them on the server via a console command., (*1)

Installation

Get the library code:, (*2)

$ cd /path/to/app/libraries
$ git clone https://github.com/Knodes/li3_ensureindex.git

Make sure it's added on app/config/bootstrap/libraries.php:, (*3)

Libraries::add('li3_ensureindex');

Index Definition

To define your indexes inside your model, just add a static and public _indexes property, such as:, (*4)

static public $_indexes = array(
    'indexname' =>  array(
        'keys' => array('somefield' => -1)
    )
);

That's it. The 'indexname' key will be used as the index name in Mongo. Other options detault to these:, (*5)

'unique' => false,
'dropDups' => false,
'background' => true,
'safe' => true,
'timeout' => 10000

And can be overwritten easily:, (*6)

static public $_indexes = array(
    'indexname' =>  array(
        'keys' => array('somefield' => -1),
        'background' => false,
    ),

    'anotherindex' =>  array(
        'keys' => array('anotherfield' => -1, 'athirdfield' => 1),
        'unique' => true,
        'dropDups' => true,
        'safe' => false
    ),

);

Please note that MongoCollection::ensureIndex restrictions apply of course, as described in the docs., (*7)

Ensuring Indexes

This library comes with a console command to ensure the defined indexes. Ensuring all indexes defined for all models is as simple as:, (*8)

li3 ensure-indexes

And will result in a detailed report of which indexes were created. Please note that existing indexes are not deleted from the collections., (*9)

It's also possible to limit the index ensure to a specific model by supplying it as a parameters:, (*10)

li3 ensure-indexes --model=MyModel

The Versions

16/10 2013

dev-master

9999999-dev https://github.com/Knodes/li3_ensureindex

  Sources   Download

The Requires

 

mongodb lithium li3 indexes