Добро пожаловать на форум PHP программистов!
За последние 24 часа нас посетил 116751 программист и 7662 робота. Сейчас ищут 2370 программистов ...
Приступая к работе

Creating An Index

Вернуться к: Tutorial

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;

$collection->ensureIndex( array( "i" => 1 ) );  // create index on "i"
$collection->ensureIndex( array( "i" => -1, "j" => 1 ) );  // 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.



Вернуться к: Tutorial

© 2026 «PHP.RU — Сообщество PHP-Программистов»
Главная | Форум | Реклама на сайте | Контакты
Разработка компании ODWR