略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: 建立索引

2024-05-06

建立索引

MongoDB 支持索引,并且很容易给集合添加索引。你需要指定字段名和排序方向: 升序(1)或降序(-1)。例如:

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

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

当你的数据量变得越来越大,创建索引对读取性能有巨大的提升。如果你不了解索引,可以参考 MongoCollection::ensureIndex() 文档和 MongoDB 的 » MongoDB indexing documentation

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/mongo.tutorial.indexes.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3