Mongoyii And Connection Using Openshift

I have successfully uploaded the yii template application to OpenShift and added the MongoDB (version 2.2) service to my app. However I don’t seem to be able to make the connection.

OpenShift give me the following information (slightly changed here for security):


MongoDB 2.2 database added.  Please make note of these credentials:

   Root User:     admin

   Root Password: 3Uhu78sikjat

   Database Name: newmdb

Connection URL: mongodb://$OPENSHIFT_MONGODB_DB_HOST:$OPENSHIFT_MONGODB_DB_PORT/

This is what I have added to the main.php file


'mongodb' => array(

			'class' => 'EMongoClient',

			'server' => 'mongodb://admin:3Uhu78sikjat@$OPENSHIFT_MONGODB_DB_HOST:$OPENSHIFT_MONGODB_DB_PORT/',

			'db' => 'newmdb'

		),

I have been able to get this working locally but cannot connect once uploaded to the host service. Any ideas what I’m doing wrong? This is the message i get from the server…


Failed to connect to: $OPENSHIFT_MONGODB_DB_HOST:0: No such file or directory

Eventually got this to work by SSH into the remote server on OpenShift get the values of the environment variables and explicitly put them into the string so that it becomes :


'mongodb' => array(

			'class' => 'EMongoClient',

			'server' => 'mongodb://admin:3Uhu78sikjat@$127.3.48.9:27017/',

			'db' => 'newmdb'

		),