How do I get individual mongo server status from mongo template in spring boot?

101 Views Asked by At

I am writing some code to periodically check db connectivity and find status of each individual member of the mongo replica set.

I want the result of the following mongo command to be accessed through spring boot's mongo template.

db.adminCommand({replSetGetStatus: 1})

When I try to access this from mongo template I am getting unauthorized error:

Bson ping = new BasicDBObject("replSetGetStatus", "1");
String test = mongoTemplate.getDb().runCommand(ping).toString();
Command failed with error 13 (Unauthorized): 'replSetGetStatus may only be run against the admin database.' 

Is there any other way to achieve what I am looking for? Thanks

0

There are 0 best solutions below