Class yii\mongodb\debug\ExplainAction

Inheritanceyii\mongodb\debug\ExplainAction » yii\base\Action
Available since extension's version2.0.5
Source Code

ExplainAction provides EXPLAIN information for MongoDB queries

Public Properties

Hide inherited properties

Property Type Description Defined By
$panel yii\mongodb\debug\MongoDbPanel Related debug toolbar panel yii\mongodb\debug\ExplainAction

Public Methods

Hide inherited methods

Method Description Defined By
run() Runs the explain action yii\mongodb\debug\ExplainAction

Protected Methods

Hide inherited methods

Method Description Defined By
explainQuery() Runs explain command over the query yii\mongodb\debug\ExplainAction

Property Details

Hide inherited properties

$panel public property

Related debug toolbar panel

Method Details

Hide inherited methods

explainQuery() protected method

Runs explain command over the query

protected array|false explainQuery ( $queryString )
$queryString string

Query log string.

return array|false

Explain results, false on failure.

                protected function explainQuery($queryString)
    /* @var $connection \yii\mongodb\Connection */
    $connection = $this->panel->getDb();
    $queryInfo = Json::decode($queryString);
    if (!isset($queryInfo['ns'])) {
        return false;
    list($databaseName, $collectionName) = explode('.', $queryInfo['ns'], 2);
    if (!empty($queryInfo['filer'])) {
        $queryInfo['filer'] = $this->prepareQueryFiler($queryInfo['filer']);
    return $connection->createCommand($databaseName)->explain($collectionName, $queryInfo);

run() public method

Runs the explain action

public string run ( $seq, $tag )
$seq integer
$tag string
return string

Explain result content

throws \yii\web\HttpException

if requested log not found

                public function run($seq, $tag)
    $timings = $this->panel->calculateTimings();
    if (!isset($timings[$seq])) {
        throw new HttpException(404, 'Log message not found.');
    $query = $timings[$seq]['info'];
    if (strpos($query, 'find({') !== 0) {
        return '';
    $query = substr($query, strlen('find('), -1);
    $result = $this->explainQuery($query);
    if (!$result) {
        return '';
    return Json::encode($result, JSON_PRETTY_PRINT);