If you're connecting using a public IP and have added'replicaSet' in the connection string but still encounter a connection error, try adding directConnection=true
directConnection=true