public function __construct($collectionOrUrl, $db = null, $collection = null)
{
if ($collectionOrUrl instanceof \MongoDB\Collection) {
$this->collection = $collectionOrUrl;
return;
}
if (!is_string($collectionOrUrl)) {
throw new \InvalidArgumentException('$collectionOrUrl was not a string');
}
if (!is_string($db)) {
throw new \InvalidArgumentException('$db was not a string');
}
if (!is_string($collection)) {
throw new \InvalidArgumentException('$collection was not a string');
}
$mongo = new \MongoDB\Client($collectionOrUrl, [], ['typeMap' => ['root' => 'array', 'document' => 'array', 'array' => 'array']]);
$mongoDb = $mongo->selectDatabase($db);
$this->collection = $mongoDb->selectCollection($collection);
}