Skip to content

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

  1. Open MongoDB Atlas.
  2. Sign In or Create Account.
  3. 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
create-mongodb-cluster

4.Create Database Access User (in example myUser and myPwd). create-mongodb-user

Use MongoDB Atlas cluster in Cloud Foundry

  1. In MongoDB Atlas, navigate to your project and select Clusters.
    Click on CONNECT button of your cluster that you want to connect to. Select Connect your application.
    connection-string
  2. Select your driver and version.
  3. Copy the connection string
    Example:
    mongodb+srv://myUser:<password>@mycluster-80us0.mongodb.net/test?retryWrites=true&w=majority
  4. Replace <password> with your password, you have created above (in example myPwd).
  5. With this change, you will have a connection string like this:

        mongodb+srv://myUser:myPwd@mycluster-80us0.mongodb.net/ test?retryWrites=true&w=majority
    

  6. 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.
    cloudfoundry-ip-addresses

Last update: August 9, 2023

Except where otherwise noted, content on this site is licensed under the Development License Agreement.