From 1c4a998249815eb34f301096f115076ce122e992 Mon Sep 17 00:00:00 2001 From: Juan Pablo Crossley Date: Wed, 10 Apr 2024 11:52:45 +0200 Subject: [PATCH] Fixed an issue with the hostname when running the script using mongosh, the hostname is not available. The method db.printSlaveReplicationInfo is deprecated and it got replaced by db.printSecondaryReplicationInfo --- getMongoData/getMongoData.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/getMongoData/getMongoData.js b/getMongoData/getMongoData.js index ab9440a..9556e0b 100644 --- a/getMongoData/getMongoData.js +++ b/getMongoData/getMongoData.js @@ -277,7 +277,7 @@ function printReplicaSetInfo() { printInfo('Replica set config', function(){return rs.conf()}, section); printInfo('Replica status', function(){return rs.status()}, section); printInfo('Replica info', function(){return db.getReplicationInfo()}, section); - printInfo('Replica slave info', function(){return db.printSlaveReplicationInfo()}, section, true); + printInfo('Replica slave info', function(){return db.printSecondaryReplicationInfo()}, section, true); } function printUserAuthInfo() { @@ -580,6 +580,10 @@ if (! _printJSON) { print("getMongoData.js version " + _version); print("================================"); } +if (typeof hostname !== 'function') { + hostname = require('os').hostname; +} + var _host = hostname(); try { @@ -588,6 +592,7 @@ try { printUserAuthInfo(); printDataInfo(isMongoS); } catch(e) { + print(e); // To ensure that the operator knows there was an error, print the error // even when outputting JSON to make it invalid JSON. print('\nERROR: '+e.message);