I am trying to capture mongo replica set state from mongo shell. E.g.
[root@server ~]$ mongo
MongoDB shell version v3.6.8
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.8
rs0:SECONDARY>
I'd like to capture that SECONDARY
keyword, and to do it in one command. I've tried something like mongo > output
, however it requires a manual ctrl+c
to terminate the process.
I have tried parse rs.status() output to display one secondary node for mongodump destination
But the solution doesn't always work. Different mongo version can output different message. ARBITER
node does not have authentication data either.