The reason you are getting an error is because `db.getReplicationInfo()` is not a command. In fact in its a function in the shell, you can print the function in the shell by removing the parentheses, which gives:
MongoDB Enterprise > db.getReplicationInfo
function () {
var localdb = this.getSiblingDB("local");
var result = { };
var oplog;
var localCollections = localdb.getCollectionNames();
if (localCollections.indexOf('oplog.rs') >= 0) { }
else if (localCollections.indexOf('oplog.$main') >= 0) {
oplog = 'oplog.$main';
}
else {
result.errmsg = "neither master/slave nor replica set replication detected";
return result;
}
var ol = localdb.getCollection(oplog);
var ol_stats = ol.stats();
if( ol_stats && ol_stats.maxSize ) {
result.logSizeMB = ol_stats.maxSize / ( 1024 * 1024 );
} else {
result.errmsg = "Could not get stats for local."+oplog+" collection. " +
"collstats returned: " + tojson(ol_stats);
return result;
}
result.usedMB = ol_stats.size / ( 1024 * 1024 );
result.usedMB = Math.ceil( result.usedMB * 100 ) / 100;
var firstc = ol.find().sort({$natural:1}).limit(1);
var lastc = ol.find().sort({$natural:-1}).limit(1);
if( !firstc.hasNext() || !lastc.hasNext() ) {
result.errmsg = "objects not found in local.oplog.$main -- is this a new and empty db instance?";
result.oplogMainRowCount = ol.count();
return result;
}
var first = firstc.next();
var last = lastc.next();
var tfirst = first.ts;
var tlast = last.ts;
if( tfirst && tlast ) {
tfirst = DB.tsToSeconds( tfirst );
tlast = DB.tsToSeconds( tlast );
result.timeDiff = tlast - tfirst;
result.timeDiffHours = Math.round(result.timeDiff / 36)/100;
result.tFirst = (new Date(tfirst*1000)).toString();
result.tLast = (new Date(tlast*1000)).toString();
result.now = Date();
}
else {
result.errmsg = "ts element not found in oplog objects";
}
return result;
}
So you'd need to replicate the whole function and its logic in the java driver.