PHPackages                             knodes/li3\_ensureindex - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. knodes/li3\_ensureindex

ActiveLithium-library

knodes/li3\_ensureindex
=======================

37232PHP

Since Oct 16Pushed 12y ago3 watchersCompare

[ Source](https://github.com/Knodes/li3_ensureindex)[ Packagist](https://packagist.org/packages/knodes/li3_ensureindex)[ RSS](/packages/knodes-li3-ensureindex/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

li3\_ensureindex
================

[](#li3_ensureindex)

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

Installation
------------

[](#installation)

Get the library code:

```
$ 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`:

```
Libraries::add('li3_ensureindex');

```

Index Definition
----------------

[](#index-definition)

To define your indexes inside your model, just add a static and public \_indexes property, such as:

```
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:

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

```

And can be overwritten easily:

```
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](http://www.php.net/manual/en/mongocollection.ensureindex.php).

Ensuring Indexes
----------------

[](#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:

```
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.

It's also possible to limit the index ensure to a specific model by supplying it as a parameters:

```
li3 ensure-indexes --model=MyModel

```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e11ad2f75cb1d558136f1982458d541d96fb84a217d6a82e8c18df2ff503964b?d=identicon)[leek](/maintainers/leek)

---

Top Contributors

[![leek](https://avatars.githubusercontent.com/u/60204?v=4)](https://github.com/leek "leek (2 commits)")[![nervetattoo](https://avatars.githubusercontent.com/u/45449?v=4)](https://github.com/nervetattoo "nervetattoo (2 commits)")[![omeryar](https://avatars.githubusercontent.com/u/189263?v=4)](https://github.com/omeryar "omeryar (2 commits)")[![JohnnyGoods](https://avatars.githubusercontent.com/u/799182?v=4)](https://github.com/JohnnyGoods "JohnnyGoods (1 commits)")

### Embed Badge

![Health badge](/badges/knodes-li3-ensureindex/health.svg)

```
[![Health](https://phpackages.com/badges/knodes-li3-ensureindex/health.svg)](https://phpackages.com/packages/knodes-li3-ensureindex)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
