Is there a way to track Node state change in MongoDB Replica set

Hi Team,

Can we capture state changes in MongoDB replica set.
For Ex.
Node1 was primary yesterday.
Today it became secondary due to weekly maintenance on Node1.

Is there a way If we would like to track these changes such as previous state of Node1 and current state of Node1 and when the state was changed.

Thanks

Hi @venkata_reddy,

Replica set member history is typically tracked by way of a monitoring solution which will generally also include proactive alerting for changes of interest (for example, increasing replication lag or election of a new primary).

See Monitoring for MongoDB for a list of some common tools, services, and server commands used.

You can also derive replication history like replica member state changes and reconfiguration from the MongoDB server logs, but I would usually reserve that effort for diagnostic investigation when changes cannot be adequately explained via your monitoring solution.

Regards,
Stennie