Hook into Replset Status/Configuration Changes

Is there a way to easily call a procedure/hook on Replset status changes (such a new member being elected Primary)?

Hi @Navbryce,

If your MongoDB cluster is deployed in Atlas, you could configure the alerts. i.e. Replica Set Elected A New Primary alert.

You could then configure a hook for the recipients of the alert, for example via Slack, etc.

Regards,
Wan.

1 Like

Thanks for the response Wan! If we’re not using Atlas, what’s our best option to retrieve this information? Polling (via getReplStatus and getReplfConf) regularly and checking for changes in something like ‘MyState’ for statuses and ‘Version’ for configs?

Hi @Navbryce,

If the cluster is not hosted on MongoDB Atlas, then performing a periodic replSetGetStatus database command is a possible solution to monitor the replica set.

Regards,
Wan.