failed with not authorized on admin to execute command { replSetHeartbeat

I got the above error while trying to build a replica set in MongoDB.

If you have security:

  authorization: enabled

Then you need to set up Internal Authentication. This is a kind of password that nodes will use to authenticate that they are part of a network, and can access each other.

Here's the document that explains setting up Internal Authentication.