Skip to content

Commit cd12678

Browse files
committed
Use server binary to get version
The `mongosh` command we want to use as client has different versioning compared to the server, this used to be the same versioning when the old client was used.
1 parent b4f0d17 commit cd12678

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/facter/mongodb_version.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
Facter.add(:mongodb_version) do
44
setcode do
5-
if Facter::Core::Execution.which('mongo')
6-
mongodb_version = Facter::Core::Execution.execute('mongo --version 2>&1')
7-
%r{MongoDB shell version:?\s+v?([\w.]+)}.match(mongodb_version)[1]
5+
if Facter::Core::Execution.which('mongod')
6+
mongodb_version = Facter::Core::Execution.execute('mongod --version 2>&1')
7+
%r{^db version:?\s+v?([\w.]+)}.match(mongodb_version)[1]
88
end
99
end
1010
end

spec/unit/mongodb_version_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
describe 'mongodb_version' do
1111
context 'with value' do
1212
before do
13-
allow(Facter::Core::Execution).to receive(:which).with('mongo').and_return(true)
14-
allow(Facter::Core::Execution).to receive(:execute).with('mongo --version 2>&1').and_return('MongoDB shell version: 3.2.1')
13+
allow(Facter::Core::Execution).to receive(:which).with('mongod').and_return(true)
14+
allow(Facter::Core::Execution).to receive(:execute).with('mongod --version 2>&1').and_return('db version v5.0.6')
1515
end
1616

1717
it {
18-
expect(Facter.fact(:mongodb_version).value).to eq('3.2.1')
18+
expect(Facter.fact(:mongodb_version).value).to eq('5.0.6')
1919
}
2020
end
2121
end

0 commit comments

Comments
 (0)