This was asked on stackoverflow and is a copy.
My Java app is using gradle and the mongo-spring starter dependency: implementation('org.springframework.boot:spring-boot-starter-data-mongodb')
.
I can connect to a publicly accessible CosmosDB with just inputting these environment variables and the mongo starter takes care of the rest. I do not have a config file for Cosmos.
MONGO_DB_HOST= cosmos-public.mongo.cosmos.azure.com MONGO_DB_DATABASE_NAME= test-db MONGO_DB_USERNAME= cosmos-public MONGO_DB_PASSWORD= [primary password] MONGO_DB_PORT= 10255 MONGO_DB_URI= mongo://cosmos-public:[password]@cosmos-public:10255/?ssl=true
I also have a CosmosDB Mongo service that has its public access disabled.
- Under "Private access" it has the connection to a private endpoint
cosmos-private-private-endpoint
- The private endpoint is connected to a virtual network/subnet called
nonprod-vnet/private-endpoints
- The private endpoint has a DNS configuration. There are 2 FDQNs:
cosmos-private.privatelink.mongo.cosmos.azure.com
cosmos-private-eastus2.privatelink.mongo.csomos.azure.com
- I am not able to access data about the Private DNS zone, as that is owned by someone else.
Can I just change my environment variables in my Java app to change it to access this private CosmosDB service? Or is there more involved I don't know about?