This blog will demonstrate how to get started with a simple MongoDB based application

 

  • Run it on Oracle Application Container cloud
  • Unit test and CI/CD using Oracle Developer cloud
  • Our MongoDB instance will run in a Docker container on Oracle Container cloud

 

 

 

Application

The sample project is relatively simple

 

  • Its uses JPA to define the data layer along with Hibernate OGM
  • Fongo (in-memory Mongo DB) is used for unit testing
  • Jersey (the JAX-RS implementation) is used to provide a REST interface

 

You can check out the project here

 

MongoDB, Hibernate OGM

MongoDB is an open source, document-based, distributed database.. More information here. Hibernate OGM is a framework which helps you use JPA (Java Persistence API) to work with NoSQL stores instead of RDBMS (which JPA was designed for)

 

  • It has support for a variety of NoSQL stores (document, column, key-value, graph)
  • NoSQL databases it supports include MongoDB (as demonstrated in this blog), Neo4j, Redis, Cassandra etc.

 

More details here

 

In this application

 

  • We define our entities and data operations (create, read) using plain old JPA
  • Hibernate OGM is used to speak JPA with MongoDB using the native Mongo DB Java driver behind the scenes. We do not interact with/write code on top of the Java driver explicitly

 

Here is a snippet from the persistence.xml which gives you an idea of the Hibernate OGM related configuration

 

Setup

Let's configure/setup our Cloud services and get the application up and running...

MongoDB on Oracle Container Cloud

 

 

 

 

Oracle Developer Cloud

You would need to configure Developer Cloud for the Continuous Build as well as Deployment process. You can refer to previous blogs for the same (some of the details specific to this example will be highlighted here)

 

References

 

Make sure you setup Oracle Developer Cloud to provide JUnit results

 

Provide Oracle Application Container Cloud (configuration) descriptor

 

As a part of the Deployment configuration, we will provide the deployment.json details to Oracle Developer Cloud - in this case, it's specifically for setting up the MongoDB co-ordinates in the form of environment variables. Oracle Developer cloud will deal with the intricacies of the deployment to Oracle Application Container Cloud

 

 

JUnit results in Oracle Developer Cloud

 

From the build logs

 

 

From the test reports

 

 

Deployment confirmation in Oracle Developer Cloud

 

 

Post-deployment status in Application Container Cloud

 

Note that the environment variables were seeded during deployment

 

 

Test the application

  • We use cURL to interact with our application REST endpoints, and
  • Robomongo as a (thick) client to verify data in Mongo DB

 

Check the URL for the ACCS application first

 

Add employee(s)

 

curl -X POST https://my-accs-app/employees -d 42:abhirockzz
curl -X POST https://my-accs-app/employees -d 43:john
curl -X POST https://my-accs-app/employees -d 44:jane

 

The request payload is ':' delimited string with employee ID and name

 

Get employee(s)

 

You will get back a XML payload in response

 

curl -X GET https://my-accs-app/employees - all employees
curl -X GET https://my-accs-app/employees/44 - specific employee (by ID)

 

 

Let's peek into MongoDB as well

 

  • mongotest is the database
  • EMPLOYEES is the MongoDB collection (equivalent to @Table in JPA)

 

 

Test the CI/CD flow

Make some code changes and push them to the Developer Cloud service Git repo. This should

  • Automatically trigger the build, which once successful will
  • Automatically trigger the deployment process, and
  • Redeploy the new application version to Application Container Cloud

 

 

**The views expressed in this post are my own and do not necessarily reflect the views of Oracle.