Manage your Mongo Databases in RHMAP with Mongo Express

Red Hat Mobile Application Platform (RHMAP) supports an agile approach to developing, integrating, and deploying enterprise mobile applications. Most likely, your mobile apps will include one or more cloud apps which will require persistence support such as a Mongo Database. But managing databases is not always easy, as command line support for this databases is complex and not always available.

To ease this pain, Mongo Express can be used as an database GUI. For the mongo databases in your cloud apps, it is a powerful and intuitive tool which can be used in conjunction or as substitute for the default database browser. The main benefits from using “Mongo Express” instead of “Data Browser” are:

Can run complex queries

In-depth stats for every view

Supports BSON types as TimeStamp() or DBRef()

IMPORTANT: there are some implications when using Mongo Express as a database manager:

Mongo Express can only manage the databases in one Cloud App and environment at a time

There is no authentication by default when using Mongo Express as explained in this article so take into account all the security issues that this may arise [1]

Users running the platform on the RHMAP should upgrade their databases if it was not upgraded before

[1] Check the Annex ‘how to add authentication’ to overcome this issue

Integrate Mongo Express as a Cloud App

Mongo Express can be installed as a cloud app and, by using the right configuration, talk to other app’s database. Here you can find out how to install and configure Mongo Express to manage your Cloud App’s Mongo database.

1. Identify our cloud app’s MongoDB url

Once we have our cloud app properly set up within our project we need to identify what is its mongo connection URL so the service can connect to it. We can get this URL from the App Studio in Environment Variables > System Environment variables (inside our cloud app).

The url should be stored in an environment variable called FH_MONGODB_CONN_URL [2]

We need to save the value of this variable so we can use it later when configuring our Mongo Express service.

2. Import Mongo Express as a Cloud App in the studio

In the ‘Apps, Cloud Apps & Services’ section of your project click on the ‘+’ sign to add a new Cloud App.

3. Mount Mongo Express as middleware in your app

4. Commit, push and deploy you app

At this point your app should be ready to be deployed. You only need to commit the changes you made, push them and deploy the app. Mongo Express will be available at: https://<your_app’s_url>/mongo_express

Annex: how to add authentication

A basic authentication mechanism can be set up in place easily. In this guide we used two npm packages to achieve this:

basic-auth (to benefit from the HTTP basic authentication mechanism)

rhmap-auth (to use RHMAP’s authentication check)

The easiest way of achieving authentication is by creating a middleware function which asks for the credentials and checks their validity with RHMAP’s authentication method: