Connecting Pacman to MongoDB Atlas

Exercise : Accessing the database access menu for configuring and monitoring

As part of this exercise we will deploy and connect to a MongoDB Atlas Cloud Database where the pacman application will store information such as high scores and user stats.

You can access the Red Hat OpenShift Database Access page from the OpenShift console navigation menu to select the correct project namespace for importing a cloud-database provider account.

If using MongoDB Atlas as a cloud-database provider, then you must add the IP address of the application pod to MongoDB Atlas' IP Access List. If the IP address is not in the IP Access List, then a 504 gateway timeout error occurs. Visit the MongoDB Atlas website for more details on adding an IP address to your database project.

Prerequisites
  • A service account with either the MongoDB Atlas, or Crunchy Data Bridge, or CockroachDB cloud database provider.

  • Procedure

  • Log into the OpenShift console.

  • To select the correct project namespace follow these sub-steps.

    Single page screenshot of the administrator’s entry point
    1. Select the Administrator perspective First callout.

    2. Expand the Data Services navigation menu, and click Database Access Second callout.

      You might need to scroll down the navigation menu.
  • Click the Project dropdown menu and then enable the Show default projects switch Third callout.

  • Type dbaas in the search field.

  • Select redhat-dbaas-operator or openshift-dbaas-operator project namespace Fourth callout.

    From the database inventory page you can monitor the database environment, import cloud-hosted database provider accounts, or create new database instances.

    Database inventory landing page

Exercise: Find your MongoDB Atlas account credentials

You need the Organization ID, the Organization Public Key, and the Organization Private Key to create a provider account resource for MongoDB Atlas.

If using MongoDB Atlas as a cloud-database provider, then you must add the IP address of the application pod to MongoDB Atlas' IP Access List. If the IP address is not in the IP Access List, then a 504 gateway timeout error occurs. Visit the MongoDB Atlas website for more details on adding an IP address to your database project.

Procedure

  • From the MongoDB Atlas home page, Sign In to your account.

  • From your account home page:

    Single screenshot for finding your Organization ID value
  • Select Organization from the dropdown menu First callout.

  • Click Settings from the Organization navigation menu Second callout.

    1. Copy the Organization ID value Third callout.

      In some cases your organization ID may be hidden by default.
      1. Next, from the account home page:

        Single screenshot for finding your API keys
  • Click Access Manager from the Organization navigation menu First callout.

  • Click API Keys Second callout.

    1. If you have existing API keys, you can find them listed here. Copy the API public and private keys for the import provider account fields. Also, verify that your API keys have the Organization Owner and Organization Member permissions Third callout Fourth callout.

  • If you need new API keys, click Create API Key, and proceed to the next step.

    Create API Key button
    1. On the Create API Key page, enter a Description, and under the Organization Permissions dropdown box select the Organization Owner and Organization Member permissions. Click Next.

      Create API Key permissions
  • Copy the API public and private keys for the import provider account fields.

View Provider Accounter in the Console

Provider Account

Exercise: Accessing the developer workspace and adding a database instance

  • Log into the OpenShift console.

  • Access the developer workspace, and select or create your project, then select a cloud-hosted database provider to add to your project:

    Single page screenshot of the developer’s entry point
  • Select the Developer perspective First callout.

  • Click +Add Second callout.

  • Click the Project dropdown menu Third callout.

  • Create a new project or search for your application’s project Fourth callout.

  • Select the Cloud-Hosted Databases tile to connect to a cloud-database provider Fifth callout.

  • Select your cloud-hosted database provider tile.

  • Click Add to Topology.

  • Select a previously configured Provider Account for this database instance from the dropdown menu.

  • Select the database instance ID you want to use, and then click Add to Topology.

  • Click Continue. Upon a successful connection, you are taken to the Topology page.

  • In the Developer Perspective, click add and select connect database from the list of available options on each cluster.

Application architecture
  • Once above step is performed, you would be able to see as shown below in developer perspective

Application architecture
  • Finally, to connect application to the database, we need to create a service binding by doing a drag and drop from the application to the connected database which will prompt a message as shown below

Application architecture
  • After successfully creating the service binding application will be connected to the database

Application architecture

Exercise: Play Pacman and save your high scores

To play Pacman, please click on the URL : Pacman Game

Pacman Game