MongoDB run command replSetGetStatus from Java driver

Viewed 1485

I want to retrieve the detailed status of each member of a replica set in Java driver as a BSON document and then process that document. However, I am having problem with the retrieving step. My code is as following:

MongoClient shard = new MongoClient(new MongoClientURI("mongodb://" + shardUri));

BasicDBObject replStatCmd = new BasicDBObject("replSetGetStatus", 1);
Document replStatus = shard.getDatabase("admin").runCommand(replStatCmd);

System.out.println(replStatus);

I can run this command in the admin database of Mongo shell. But my implementation in Java returns nothing as document and the code never gets to the line println(). Can anyone give me some suggestions ?

1 Answers
Related