I have an application running on JBossAS7 with MongoDB as database. The application is able to connect to the local MongoDB and perform data operations as expected. When I attempt to connect to the remote MongoDB hosted on OpenShift, the database connection can not be made.
After creating an OpenShift application and adding MongoDB cartridge, I ssh-ed to the OpenShift application server and typed in the command env | grep OPENSHIFT_MONGODB_DB
env | grep OPENSHIFT_MONGODB_DB
to retrieve MongoDB host information as displayed below:
OPENSHIFT_MONGODB_DB_USERNAME=...
OPENSHIFT_MONGODB_DB_PASSWORD=...
OPENSHIFT_MONGODB_DB_HOST=...
OPENSHIFT_MONGODB_DB_GEAR_DNS=...
OPENSHIFT_MONGODB_DB_PORT=...
OPENSHIFT_MONGODB_DB_URL=...
OPENSHIFT_MONGODB_DB_GEAR_UUID=...
Since I am using DataNucleus JDO, following is how I set the properties of Persistence Manager Factory (PMF) in the JBoss application in hope to connect to OpenShift MongoDB with the above information:
properties.setProperty("javax.jdo.option.ConnectionURL","mongodb://[OPENSHIFT_MONGODB_DB_HOST]:[OPENSHIFT_MONGODB_DB_PORT]/[Database Name]");
properties.setProperty("javax.jdo.option.ConnectionUserName",[OPENSHIFT_MONGODB_DB_USERNAME]);
properties.setProperty("javax.jdo.option.ConnectionPassword",[OPENSHIFT_MONGODB_DB_PASSWORD]);
Would really appreciate the help here. Thank you :)
Simple inspection of documentation shows that
mongodb://[OPENSHIFT_MONGODB_DB_HOST]:[OPENSHIFT_MONGODB_DB_PORT]/[Database Name]
is invalid syntax. There are no double slashes in accepted syntax (unless your hostname really begins with double slash, which I doubt)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.