Regarding the secondary replica connection string

I configured replica set in such a way that the the primary and secondary are two different VMs so that i could able to get My API’s hit to the secondary to get the results form it so that it won’t affect the primary and the data which i have is always upto date.

Now the issue is the secondary replica set connection URL, I could able to connect the same credentials form tools such and robo 3t but when it comes to connection string placement it is showing the following error “getaddrinfo ENOTFOUND mongo.explorer.replica.#####.com”. and couldn’t able to access the same URL or the credentials from Mongo compass.

It would be very helpful if i get a solution to solve this issue.and may i know the reason why the mongo secondary replica i could able to connect through robo 3t and not via mongo compass.

You should have 3 nodes in your replica set. See https://www.mongodb.com/docs/manual/replication/.

What you are doing is based on the wrong assumption that a secondary has less work to do than the primary. To have up to date data on secondaries, the secondaries do exactly the same writes as the primary. If you keep them busy with read work load because your primary is not powerful enough to do both, your secondaries probably cannot do both, so they will eventually be behind the primary oplog and the data on your secondaries will not be up to date.

As for ENOTFOUND, it is not mongodb specific, it is a DNS setup that is not correct. You have some DNS information that is not propagated to all resolvers. Try to connect with mongodb only once you are able to ping the same address.