略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: MongoCursor::explain

2024-12-24

MongoCursor::explain

(PECL mongo >=0.9.2)

MongoCursor::explainReturn an explanation of the query, often useful for optimization and debugging

说明

public MongoCursor::explain ( void ) : array

参数

此函数没有参数。

返回值

Returns an explanation of the query.

范例

Example #1 MongoCursor::explain() example

<?php

$cursor 
$collection->find(array("x"=>1), array("y"));
$cursor->sort(array("z" => 1))->limit(4)->skip(5);

var_dump($cursor->explain());

?>

以上例程的输出类似于:

array(8) {
  ["cursor"]=>
  string(15) "BtreeCursor x_1"
  ["startKey"]=>
  array(1) {
    ["x"]=>
    int(1)
  }
  ["endKey"]=>
  array(1) {
    ["x"]=>
    int(1)
  }
  ["nscanned"]=>
  float(4)
  ["n"]=>
  int(4)
  ["scanAndOrder"]=>
  int(1)
  ["millis"]=>
  int(3)
  ["allPlans"]=>
  array(2) {
    [0]=>
    array(3) {
      ["cursor"]=>
      string(15) "BtreeCursor x_1"
      ["startKey"]=>
      array(1) {
        ["x"]=>
        int(1)
      }
      ["endKey"]=>
      array(1) {
        ["x"]=>
        int(1)
      }
    }
    [1]=>
    array(3) {
      ["cursor"]=>
      string(11) "BasicCursor"
      ["startKey"]=>
      array(0) {
      }
      ["endKey"]=>
      array(0) {
      }
    }
  }
}

错误/异常

Throws MongoConnectionException if it cannot reach the database.

参见

MongoDB core docs on » explain.

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/mongocursor.explain.php

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