MongoDB is a NoSQL database that can use indexes to speed particular ad-hoc searches. You can add an index to a particular MongoDB field very easily from PHP.
You can add an index easily with the ensureIndex() method on a collection object. To add a simply ascending index, just use this command:
$result = $myCollection->ensureIndex(array($myField=>1));
The value of 1 specifies an ascending index. For descending, use a -1 value:
$result = $myCollection->ensureIndex(array($myField=>-1));
You can specify a multi-key index by passing an multi-element array like this:
$result = $myCollection->ensureIndex(array($myField=>1,$mySecondField=>-1));
These commands will create an index if one doesn't exist and return a reference to the existing index if it is already setup on the collection.



Del.ici.ous


