hostname
TypeError: db.hostInfo is not a function
ReferenceError: hostname is not defined
Can someone help me how i can find the connected mongo instance server name using the node.js script?
Thanks,
Amit
Can someone help me how i can find the connected mongo instance server name using the node.js script?
Hi Amit,
You can try running the isMaster() command to retrieve some information about the replica set you’re connecting to. For example:
MongoClient.connect(mongo_url, function(err, db) {
assert.equal(null, err);
db.command({'ismaster':1}, function(err, result){
console.log(result);
});
db.close();
});
The code above should print out an output similar to :
{ hosts: [ 'host1:28001', 'host2:28002', 'host3:28003' ],
setName: 'replicaSetName',
setVersion: 1,
ismaster: true,
secondary: false,
primary: 'host1:27001',
me: 'host1:27001',
electionId: 7fffffff0000000000000004,
maxBsonObjectSize: 16777216,
maxMessageSizeBytes: 48000000,
maxWriteBatchSize: 1000,
localTime: 2016-11-02T01:37:14.364Z,
maxWireVersion: 4,
minWireVersion: 0,
ok: 1 }
The value of ismaster, primary and me are most likely what you’re after.
The snippet above was written for MongoDB Node.js driver v2.2 and MongoDB v3.2.x. If you have further questions, could you provide:
Regards,
Wan.