0

I am wondering if I can programmatically determine the health of the Replset through the Mongo Java Driver. What I want to know is: Where is the PRIMARY? How "caught up" are the SECONDARIES in oplog time? Is this possible and what's the API to do it?

Bob Kuhar
  • 10,838
  • 11
  • 62
  • 115

1 Answers1

1

db.command("ismaster").get("primary") : Gives you the current primary

db.getSisterDB("admin").command("replSetGetStatus").get("members") : It contains the necessary replication details for all the members. This command has to run over admin database

Hope it helps.

Abhishek Kumar
  • 3,328
  • 2
  • 18
  • 31
  • That is very promising, thanks. I'll see if I can leverage this. – Bob Kuhar Apr 30 '13 at 18:44
  • Wow. That works pretty well: CommandResult result = mongo.getDB( "admin" ).command( "replSetGetStatus" ); System.out.println( "members: " + result.get( "members" ) ); – Bob Kuhar Apr 30 '13 at 22:51