I have a deployment on k8s on my local machine which creates a pod that connects to MongoDB hosted on Atlas. It’s a spring boot project with uses auto-configuration to connect to db. I use the following properties
spring:
data:
mongodb:
uri: mongodb+srv://<username>:<pwd>@cluster.xvn1234.mongodb.net/
database: sample_mflix
I am able to connect and get the details from Mongo.
Now I create an ExternalName
for this using the following:
kind: Service
apiVersion: v1
metadata:
name: mongo
spec:
type: ExternalName
externalName: cluster.xvn1234.mongodb.net
I get inside the pod and try to use mongosh
to connect using the following command:
mongosh "mongodb+srv://cluster.xvn1234.mongodb.net/" --apiVersion 1 --username dummyUser
I am able to connect, works as expected. But when I change the connection string to the following, I cant connect to Mongo
mongosh mongodb+srv://mongo --apiVersion 1 --username dummyUser
Since I created an ExternalName, I thought i will be able to connect to it from my pod.
I have already enabled traffic from everywhere on the MongoDB cluster.
Is there something I am missing?