Endpoint returns both public IP and private IP

I have a sharded Mongo cluster that returns both the private IP and public IP.

When I try to ping/nc the endpoint from inside the container running my application, I get the public IP. But when my application tries to connect to Mongo it resolves to the private IP.

I have VPC peering between my VPC and Mongo Atlas VPC.

What could be causing this issue?

I would recommend to review the connection string being used while doing ping/nc from container and from the application.

As you are using VPC peering - the connection string would have “pri” in it, in case you are on GCP or Azure, or using custom DNS in AWS. Furthermore, verify the connection string being used.