Unable to add nodes into Replicaset

You have to use the rs.reconfig() command like below. In this example I change “localhost” to “hafx” which is my actual hostname that other computers on my network can find.

test [direct: primary] test> conf = rs.conf()
{
  _id: 'test',
  version: 2,
  term: 1,
  members: [
    {
      _id: 0,
      host: 'localhost:27017',
      arbiterOnly: false,
      buildIndexes: true,
      hidden: false,
      priority: 1,
      tags: {},
      secondaryDelaySecs: Long("0"),
      votes: 1
    }
  ],
  protocolVersion: Long("1"),
  writeConcernMajorityJournalDefault: true,
  settings: {
    chainingAllowed: true,
    heartbeatIntervalMillis: 2000,
    heartbeatTimeoutSecs: 10,
    electionTimeoutMillis: 10000,
    catchUpTimeoutMillis: -1,
    catchUpTakeoverDelayMillis: 30000,
    getLastErrorModes: {},
    getLastErrorDefaults: { w: 1, wtimeout: 0 },
    replicaSetId: ObjectId("62a35084f93f180c51796d9d")
  }
}
test [direct: primary] test> conf.members[0].host = 'hafx:27017'
hafx:27017
test [direct: primary] test> rs.reconfig(conf)
{
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1654870331, i: 1 }),
    signature: {
      hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
      keyId: Long("0")
    }
  },
  operationTime: Timestamp({ t: 1654870331, i: 1 })
}
test [direct: primary] test> rs.conf()
{
  _id: 'test',
  version: 3,
  term: 1,
  members: [
    {
      _id: 0,
      host: 'hafx:27017',
      arbiterOnly: false,
      buildIndexes: true,
      hidden: false,
      priority: 1,
      tags: {},
      secondaryDelaySecs: Long("0"),
      votes: 1
    }
  ],
  protocolVersion: Long("1"),
  writeConcernMajorityJournalDefault: true,
  settings: {
    chainingAllowed: true,
    heartbeatIntervalMillis: 2000,
    heartbeatTimeoutSecs: 10,
    electionTimeoutMillis: 10000,
    catchUpTimeoutMillis: -1,
    catchUpTakeoverDelayMillis: 30000,
    getLastErrorModes: {},
    getLastErrorDefaults: { w: 1, wtimeout: 0 },
    replicaSetId: ObjectId("62a35084f93f180c51796d9d")
  }
}

Final rs.status()

test [direct: primary] test> rs.status()
{
  set: 'test',
  date: ISODate("2022-06-10T14:12:21.947Z"),
  myState: 1,
  term: Long("1"),
  syncSourceHost: '',
  syncSourceId: -1,
  heartbeatIntervalMillis: Long("2000"),
  majorityVoteCount: 1,
  writeMajorityCount: 1,
  votingMembersCount: 1,
  writableVotingMembersCount: 1,
  optimes: {
    lastCommittedOpTime: { ts: Timestamp({ t: 1654870331, i: 1 }), t: Long("1") },
    lastCommittedWallTime: ISODate("2022-06-10T14:12:11.371Z"),
    readConcernMajorityOpTime: { ts: Timestamp({ t: 1654870331, i: 1 }), t: Long("1") },
    appliedOpTime: { ts: Timestamp({ t: 1654870331, i: 1 }), t: Long("1") },
    durableOpTime: { ts: Timestamp({ t: 1654870331, i: 1 }), t: Long("1") },
    lastAppliedWallTime: ISODate("2022-06-10T14:12:11.371Z"),
    lastDurableWallTime: ISODate("2022-06-10T14:12:11.371Z")
  },
  lastStableRecoveryTimestamp: Timestamp({ t: 1654870319, i: 1 }),
  electionCandidateMetrics: {
    lastElectionReason: 'electionTimeout',
    lastElectionDate: ISODate("2022-06-10T14:09:08.971Z"),
    electionTerm: Long("1"),
    lastCommittedOpTimeAtElection: { ts: Timestamp({ t: 1654870148, i: 1 }), t: Long("-1") },
    lastSeenOpTimeAtElection: { ts: Timestamp({ t: 1654870148, i: 1 }), t: Long("-1") },
    numVotesNeeded: 1,
    priorityAtElection: 1,
    electionTimeoutMillis: Long("10000"),
    newTermStartDate: ISODate("2022-06-10T14:09:09.484Z"),
    wMajorityWriteAvailabilityDate: ISODate("2022-06-10T14:09:09.565Z")
  },
  members: [
    {
      _id: 0,
      name: 'hafx:27017',
      health: 1,
      state: 1,
      stateStr: 'PRIMARY',
      uptime: 197,
      optime: { ts: Timestamp({ t: 1654870331, i: 1 }), t: Long("1") },
      optimeDate: ISODate("2022-06-10T14:12:11.000Z"),
      lastAppliedWallTime: ISODate("2022-06-10T14:12:11.371Z"),
      lastDurableWallTime: ISODate("2022-06-10T14:12:11.371Z"),
      syncSourceHost: '',
      syncSourceId: -1,
      infoMessage: '',
      electionTime: Timestamp({ t: 1654870148, i: 2 }),
      electionDate: ISODate("2022-06-10T14:09:08.000Z"),
      configVersion: 3,
      configTerm: 1,
      self: true,
      lastHeartbeatMessage: ''
    }
  ],
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1654870331, i: 1 }),
    signature: {
      hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
      keyId: Long("0")
    }
  },
  operationTime: Timestamp({ t: 1654870331, i: 1 })
}