Skip to content

Commit 17a5328

Browse files
committed
Implement Connection::getServerVersion
1 parent f654b83 commit 17a5328

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-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

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use MongoDB\Driver\ReadPreference;
1616
use MongoDB\Laravel\Concerns\ManagesTransactions;
1717
use OutOfBoundsException;
18+
use Override;
1819
use Throwable;
1920

2021
use function filter_var;
@@ -327,6 +328,12 @@ public function __call($method, $parameters)
327328
return $this->db->$method(...$parameters);
328329
}
329330

331+
#[Override]
332+
public function getServerVersion(): string
333+
{
334+
return $this->db->command(['buildInfo' => 1])->toArray()[0]['version'];
335+
}
336+
330337
private static function getVersion(): string
331338
{
332339
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)