Openshift provides us a lot of environment variables, we should use them whenever possible, so that we don't have to hard code anything in our code.
The following two env variables can helps us connect to mongodb easily
OPENSHIFT_APP_NAMEthe name of your current app, for instancefooOPENSHIFT_MONGODB_DB_URLthe full address of mongodb server, which looks likemongodb://admin:abcdefg@127.1.2.3:27017/
The complete connection string will be
OPENSHIFT_MONGODB_DB_URL + OPENSHIFT_APP_NAME
=> mongodb://admin:abcdefg@127.1.2.3:27017/foo
Pass the connection string to your mongodb client, and you should be able to use mongodb on Openshift!