/** * @return ArrayIterator * @throws \Exception|\MongoException * @throws \RuntimeException */ public function aggregate() { $database = $this->collection->getDatabase(); $command = array(); $command['aggregate'] = $this->collection->getName(); $command['pipeline'] = $this->getPipeline(); try { $result = $database->command($command); } catch (\MongoException $e) { throw $e; } if (!$result['ok']) { throw new \RuntimeException($result['errmsg']); } return new ArrayIterator(isset($result['result']) ? $result['result'] : array()); }
/** * @return array * * @throws \Exception */ protected function getCollectionStats() { $database = $this->collection->getDatabase(); $name = $this->collection->getName(); try { if (!($data = $database->command(array('collStats' => $name)))) { $message = sprintf("Statistics not found for collection %s", $name); throw new Exception($message); } if (isset($data['errmsg'])) { throw new Exception($data['errmsg']); } return $data; } catch (Exception $e) { throw $e; } return array(); }
/** * Return the connection for this cursor. * * @deprecated 1.1 Will be removed for 2.0 * @return Connection */ public function getConnection() { return $this->collection->getDatabase()->getConnection(); }