Skip to content

Instantly share code, notes, and snippets.

@jerrymannel
Created November 26, 2019 19:38
Show Gist options
  • Save jerrymannel/e5fef73c5f172f875ba69fb9af7af826 to your computer and use it in GitHub Desktop.
Save jerrymannel/e5fef73c5f172f875ba69fb9af7af826 to your computer and use it in GitHub Desktop.
Find the mongo server version and replica set information from nodejs client.
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
var url = 'mongodb://localhost:27017';
const dbName = 'test';
const client = new MongoClient(url, { useUnifiedTopology: true });
client.connect(function(err) {
assert.equal(null, err);
console.log("Connected successfully to server");
client.db().executeDbAdminCommand({ buildInfo: 1 })
.then(_d => console.log(`MONGODB server version :: ${_d.version}`))
client.db().executeDbAdminCommand({ replSetGetStatus: 1 })
.then(_d => console.log(`REPLICASET :: ${_d.set}`),
_e => console.log(_e))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment