diff --git a/src/Connection.php b/src/Connection.php index 2ce5324ee..343c0ca21 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -327,6 +327,11 @@ public function __call($method, $parameters) return $this->db->$method(...$parameters); } + public function getServerVersion(): string + { + return $this->db->command(['buildInfo' => 1])->toArray()[0]['version']; + } + private static function getVersion(): string { return self::$version ?? self::lookupVersion(); diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 586452109..ef0b746c3 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -299,4 +299,10 @@ public function testPingMethod() $instance = new Connection($config); $instance->ping(); } + + public function testServerVersion() + { + $version = DB::connection('mongodb')->getServerVersion(); + $this->assertIsString($version); + } }