Skip to content

Commit 20eb3f6

Browse files
committed
Implement Connection::getServerVersion
1 parent f654b83 commit 20eb3f6

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [4.9.0] - coming soon
5+
6+
* Add `Connection::getServerVersion()` by @GromNaN in [#3043](https://github.com/mongodb/laravel-mongodb/pull/3043)
7+
48
## [4.6.0] - 2024-07-09
59

610
* Add `DocumentModel` trait to use any 3rd party model with MongoDB @GromNaN in [#2580](https://github.com/mongodb/laravel-mongodb/pull/2580)

src/Connection.php

+5
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ public function __call($method, $parameters)
327327
return $this->db->$method(...$parameters);
328328
}
329329

330+
public function getServerVersion(): string
331+
{
332+
return $this->db->command(['buildInfo' => 1])->toArray()[0]['version'];
333+
}
334+
330335
private static function getVersion(): string
331336
{
332337
return self::$version ?? self::lookupVersion();

tests/ConnectionTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,10 @@ public function testPingMethod()
299299
$instance = new Connection($config);
300300
$instance->ping();
301301
}
302+
303+
public function testServerVersion()
304+
{
305+
$version = DB::connection('mongodb')->getServerVersion();
306+
$this->assertIsString($version);
307+
}
302308
}

0 commit comments

Comments
 (0)