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?
Asked
Active
Viewed 599 times
1 Answers
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