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