This is how my array is set up:
"members" : [
{ "health" : 0,
"stateStr" : "Not reachable",
},
{ "health" : 1,
"stateStr" : "PRIMARY",
},
{ "health" : 1,
"stateStr" : "ARBITER",
}
],
What I'm trying to achieve is to iterate through all 3 members, and find if a member has stateStr = Primary
(in the above example, member[1] will pass this condition). If that condition passes, look at the same member and see if health=1
. In the above example, I would then look at if member[1].health =1. I'm not sure how to store that index of member.. I would appreciate it if you could show me exactly - I'm very new!
Here's the logic of it:
- If any member has stateStr=Secondary. If yes, then print "Secondary node is still running." and break.
- Else, Check if any member has stateStr="Primary". If Primary is found, check whether its health = 1
- If none of the members are Primary, then print "No primary node found" and if Primary node is found but its health !=1, then print "Primary node unhealthy" and break.
- Repeat the previous three steps for stateStr="Arbiter"