2

I have a NodeJS Express app that uses Mongoose for MongoDB. I'm confused as to how to connect it to the OpenShift database. For development, I'm connecting to a local database, which works fine. Here's what I have:

//====== MONGODB SETUP ======
mongo_url = process.env.OPENSHIFT_MONGODB_DB_HOST+":"+parseInt(process.env.OPENSHIFT_MONGODB_DB_PORT);

if(app.dev){
    mongo_url = "mongodb://localhost:27017/my-db";
}

app.modules.mongoose.connect(mongo_url);

Any help would be great!

Carpetfizz
  • 8,707
  • 22
  • 85
  • 146

2 Answers2

3

You need more than just host and port. You have to provide username and password. A simpler way for it is to use:

mongo_url = process.env.OPENSHIFT_MONGODB_DB_URL;

OPENSHIFT_MONGODB_DB_URL has username and password too.

Foad Nosrati Habibi
  • 1,134
  • 1
  • 8
  • 13
1

You have to provide username and password and the database name along with host and port.

So you can try appending OPENSHIFT_APP_NAME to the OPENSHIFT_MONGODB_DB_URL.

mongo_url = process.env.OPENSHIFT_MONGODB_DB_URL+process.env.OPENSHIFT_APP_NAME;

OPENSHIFT_MONGODB_DB_URL has the below format:
(e.g. mongodb://<username>:<password>@<hostname>:<port>/)
Harsh Gupta
  • 444
  • 3
  • 9