downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

Read Preferences> <Getting A Set of Documents With a Query
[edit] Last updated: Fri, 24 May 2013

view this page in

Creating An Index

MongoDB supports indexes, and they are very easy to add on a collection. To create an index, you specify the field name and direction: ascending (1) or descending (-1). The following creates an ascending index on the "i" field:

<?php
$connection 
= new MongoClient();
$collection $connection->database->collectionName;

$coll->ensureIndex( array( "i" => ) );  // create index on "i"
$coll->ensureIndex( array( "i" => -1"j" => ) );  // index on "i" descending, "j" ascending
?>

Indexing is critical for good read performance as your data grows. If you are not familiar with indexing, check out the MongoCollection::ensureIndex() documentation and the core » MongoDB indexing documentation.



add a note add a note User Contributed Notes Creating An Index - [0 notes]
There are no user contributed notes for this page.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites