there is the replica with three member (primary,secondary,secondary). Suppose one of secondaries down for a day, after return secondary back to replica how can i find, i
I wrote a little script for mongoDB shell. It shows a diff between optime and optimeDate. You can use it instead of comparing manually replica set members.
var isMaster = rs.isMaster();
var me = isMaster.me;
if(!isMaster.ismaster && isMaster.secondary)
{
var status = rs.status();
var master = isMaster.primary;
var masterOptime = 0;
var masterOptimeDate = 0;
var myOptime = 0;
var myOptimeDate = 0;
for(var i = 0 ; i < status.members.length ; i++)
{
var member = status.members[i];
if(member.name == me)
{
if(member.stateStr == "SECONDARY") {
myOptime = member.optime.getTime();
myOptimeDate = member.optimeDate.getTime();
}
else
{
print(me + ' is out of sync ' + member.stateStr);
break;
}
}
else if(member.name == master)
{
masterOptime = member.optime.getTime();
masterOptimeDate = member.optimeDate.getTime();
}
}
if(myOptime && myOptimeDate)
{
var optimeDiff = masterOptime - myOptime;
var optimeDateDiff = masterOptimeDate - myOptimeDate;
print('optime diff: ' + optimeDiff);
print('optimeDate diff: ' + optimeDateDiff);
}
}
else
{
print(me + ' is not secondary');
}