I have created a MongoDB
instance in OpenShift
. I can connect to it via RockMongo
, which is a service offered by OpenShift
.
OpenShift provides environment variables, which you should use to connect to your MongoDB.
OPENSHIFT_MONGODB_DB_HOST
The MongoDB IP addressOPENSHIFT_MONGODB_DB_PORT
The MongoDB portOPENSHIFT_MONGODB_DB_USERNAME
The MongoDB usernameOPENSHIFT_MONGODB_DB_PASSWORD
The MongoDB passwordOPENSHIFT_MONGODB_DB_URL
The MongoDB connection URL (e.g. mongodb://<username>:<password>@<hostname>:<port>/
)I'm using one line of code to connect to the database:
new MongoClient(new MongoClientURI(System.getenv("OPENSHIFT_MONGODB_DB_URL")));