Sokil\Mongo\Collection::explainAggregate PHP Method

explainAggregate() public method

Explain aggregation
Deprecation: use pipeline option 'explain' in Collection::aggregate() or method Pipeline::explain()
public explainAggregate ( array | Pipeline $pipeline ) : array
$pipeline array | Pipeline
return array result
    public function explainAggregate($pipeline)
    {
        if (version_compare($this->getDatabase()->getClient()->getDbVersion(), '2.6.0', '<')) {
            throw new Exception('Explain of aggregation implemented only from 2.6.0');
        }
        if ($pipeline instanceof Pipeline) {
            $pipeline = $pipeline->toArray();
        } else {
            if (!is_array($pipeline)) {
                throw new Exception('Wrong pipeline specified');
            }
        }
        // aggregate
        return $this->database->executeCommand(array('aggregate' => $this->getName(), 'pipeline' => $pipeline, 'explain' => true));
    }

Usage Example

Esempio n. 1
0
 public function testExplainAggregate()
 {
     $this->collection->createDocument(array('param' => 1))->save();
     $this->collection->createDocument(array('param' => 2))->save();
     $this->collection->createDocument(array('param' => 3))->save();
     $this->collection->createDocument(array('param' => 4))->save();
     $pipeline = $this->collection->createAggregator()->match(array('param' => array('$gte' => 2)))->group(array('_id' => 0, 'sum' => array('$sum' => '$param')));
     try {
         $explain = $this->collection->explainAggregate($pipeline);
         $this->assertArrayHasKey('stages', $explain);
     } catch (\Exception $e) {
         $this->assertEquals('Explain of aggregation implemented only from 2.6.0', $e->getMessage());
     }
 }