Using MongoDB Atlas in Cloud Foundry¶
This document describes how to bind a MongoDB instance from an own MongoDB Atlas account to an app running in Cloud Foundry.
Note
All MongoDB instances in Cloud Foundry have been deleted on 31st October 2020 as communicated.
Create MongoDB cluster MongoDB Atlas¶
- Open MongoDB Atlas.
- Sign In or Create Account.
- Create MongoDB Cluster (in example
MyCluster
).
Note
Recommendation:
For eu1 region, create it on AWS in region Frankfurt For eu2 region, create it on Azure in region westeurope
4.Create Database Access User (in example myUser
and myPwd
).
Use MongoDB Atlas cluster in Cloud Foundry¶
- In MongoDB Atlas, navigate to your project and select Clusters.
Click onCONNECT
button of your cluster that you want to connect to. SelectConnect your application
.
- Select your driver and version.
- Copy the connection string
Example:
mongodb+srv://myUser:<password>@mycluster-80us0.mongodb.net/test?retryWrites=true&w=majority
- Replace
<password>
with your password, you have created above (in examplemyPwd
). -
With this change, you will have a connection string like this:
mongodb+srv://myUser:myPwd@mycluster-80us0.mongodb.net/ test?retryWrites=true&w=majority
-
In
cf cli
, create an User-Provided-Service:
cf cups <my-mongodb.com-cluster> -p "uri"
Note
If you are using any connector for connecting to MongoDB instance, it may be required to set an tag or label to let the connector find the MongoDB URI in environment variables.
For example, Spring Cloud Cloud Foundry Connector requires a tag mongodb
. For setting the tag, you can extend your cups
command by -t "mongodb"
7.When requested for uri, insert your connection string
8.Bind User-Provided-Service to your app:
cf bs <myapp> <my-mongodb.com-cluster>
9.Restage your app:
cf restage <myapp>
Hints¶
- Remember to change the service instance name to the User-Provided-Service in your
manifest.yml
- MongoDB TLS/SSL is standard
- Latency time may be higher than before
Tip: Create DB in AWS Frankfurt to minimize the latency time - Your application may need more outbound traffic
- Note that your database endpoint is now accesible over internet. Please consider the security recommendations below and implement all additional security measures recommended by your organization.
Security Recommendations¶
- Whitelist MongoDB Atlas cluster access for Cloud Foundry IP addresses only.
You can find the Cloud Foundry IP addresses here.
Except where otherwise noted, content on this site is licensed under the Development License Agreement.