Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Connection::getServerVersion #3043

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [4.9.0] - coming soon

* Add `Connection::getServerVersion()` by @GromNaN in [#3043](https://github.com/mongodb/laravel-mongodb/pull/3043)

## [4.6.0] - 2024-07-09

* Add `DocumentModel` trait to use any 3rd party model with MongoDB @GromNaN in [#2580](https://github.com/mongodb/laravel-mongodb/pull/2580)
Expand Down
11 changes: 11 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,17 @@ public function __call($method, $parameters)
return $this->db->$method(...$parameters);
}

/**
* Return the server version of one of the MongoDB servers: primary for
* replica sets and standalone, and the selected server for sharded clusters.
*
* @internal
*/
public function getServerVersion(): string
{
return $this->db->command(['buildInfo' => 1])->toArray()[0]['version'];
alcaeus marked this conversation as resolved.
Show resolved Hide resolved
}

private static function getVersion(): string
{
return self::$version ?? self::lookupVersion();
Expand Down
6 changes: 6 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,10 @@ public function testPingMethod()
$instance = new Connection($config);
$instance->ping();
}

public function testServerVersion()
{
$version = DB::connection('mongodb')->getServerVersion();
$this->assertIsString($version);
}
}
Loading