Hello I'm trying to get Node/Mongo service going on Openshift, here's what it looks like:

 var db = new mongodb.Db('myServiceName',
   new mongodb.Server('mongodb://$OPENSHIFT_MONGODB_DB_HOST','$OPENSHIFT_MONGODB_DB_PORT', {}));
 db.open(function (err, db_p) {
   if (err) { throw err; }
   db.authenticate('$USER', '$PASS', function (err, replies) {
     if (err) { throw err; }
     // should be connected and authenticated.
     // ...

The app was created using rhc:

$ rhc create-app myServiceName nodejs-0.10 mongodb-2.4

The console shows the app was started and is running, and on cURL the response is 503

My logs don't show an error, however, the dB is obviously not live. Can anyone help?

有帮助吗?

解决方案

If your mongodb driver supports connection with username/password, then use OPENSHIFT_MONGODB_DB_URL instead of OPENSHIFT_MONGODB_DB_HOST

OPENSHIFT_MONGODB_DB_URL gives you this format:

mongodb://admin:password@127.4.99.1:27017/

and OPENSHIFT_MONGODB_DB_HOST gives you this format:

ip addres, ex: 127.4.99.1

So you can just use OPENSHIFT_MONGODB_DB_URL to connect and authenticate at the same time

with mongoskin, you can just do this:

var db = require('mongoskin').db(process.env.OPENSHIFT_MONGODB_DB_URL + 'dbname'+ '?auto_reconnect=true',
    {safe: true, strict: false}
);

其他提示

It looks like you are attempting to connect to a server named "$OPENSHIFT_MONGODB_DB_HOST", (not a valid URL).

Instead, you'll probably want to read the value of the OPENSHIFT_MONGODB_DB_HOST environment variable to find your connection information:

process.env.OPENSHIFT_MONGODB_DB_HOST

I have some additional notes up here: https://www.openshift.com/blogs/getting-started-with-mongodb-on-nodejs-on-openshift

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top