Skip to content

Commit 1a1621a

Browse files
authoredJul 15, 2024
Implement Connection::getServerVersion (#3043)
1 parent f654b83 commit 1a1621a

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
 

Diff for: ‎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)

Diff for: ‎src/Connection.php

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

330+
/**
331+
* Return the server version of one of the MongoDB servers: primary for
332+
* replica sets and standalone, and the selected server for sharded clusters.
333+
*
334+
* @internal
335+
*/
336+
public function getServerVersion(): string
337+
{
338+
return $this->db->command(['buildInfo' => 1])->toArray()[0]['version'];
339+
}
340+
330341
private static function getVersion(): string
331342
{
332343
return self::$version ?? self::lookupVersion();

Diff for: ‎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)