Internal convenience method that returns the instance of the MongoDB Collection
\MongoCollection
\RuntimeException
protected function getMongo() {
if ($this->mongo === null) {
if (preg_match('#^(mongodb://.*)/(.*)/(.*)$#', $this->dsn, $matches)) {
$server = $matches[1] . (!empty($matches[2]) ? '/' . $matches[2] : '');
$database = $matches[2];
$collection = $matches[3];
$mongoClass = version_compare(phpversion('mongo'), '1.3.0', '<') ? '\\Mongo' : '\\MongoClient';
$mongo = new $mongoClass($server);
$this->mongo = $mongo
->selectCollection($database, $collection);
}
else {
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use MongoDB with an invalid dsn "%s". The expected format is "mongodb://[user:pass@]host/database/collection"', $this->dsn));
}
}
return $this->mongo;
}