Node.js 仍然无法将一个Openshift应用程序连接到另一个Openshift应用程序';s MongoDB数据库
在遵循此处提出的建议后: …简言之,这是->“您需要将应用程序创建为可伸缩的,然后添加MongoDB以使其正常工作。然后MongoDB将使用自己的ip地址和端口号(记住使用此端口号,否则将无法正常工作)。” …我仍然无法将Node.js应用程序成功连接到Openshift中另一个Node.js应用程序上的MongoDB数据库 我尝试了以下建议的主机字符串排列:Node.js 仍然无法将一个Openshift应用程序连接到另一个Openshift应用程序';s MongoDB数据库,node.js,mongodb,Node.js,Mongodb,在遵循此处提出的建议后: …简言之,这是->“您需要将应用程序创建为可伸缩的,然后添加MongoDB以使其正常工作。然后MongoDB将使用自己的ip地址和端口号(记住使用此端口号,否则将无法正常工作)。” …我仍然无法将Node.js应用程序成功连接到Openshift中另一个Node.js应用程序上的MongoDB数据库 我尝试了以下建议的主机字符串排列: 本地主机 128.xxx.xxx.xxx [24字符哈希]-myapp-mydomain.rhcloud.com …结果都一样。没有联
dbProvider = function(host, port, user, pass) {
console.re.log("Attempting to create a DB instance...");
this.db = new Db(process.env.OPENSHIFT_MONGODB_EXTDB_DBNAME, new Server(host, port, { auto_reconnect: true }, {}));
console.re.log("created the DB instance...");
if(this.db!= null){
console.re.log("successfully connected to remote db %s at %s:%s",this.db,host,port);
this.db.open(function(error, db){
if(error){
console.re.log("error %s attempting to open the db at %s:%s",error,host,port);
}
else{
db.authenticate(user, pass, function(error, result) { //db.authenticate(user, pass, function(error, result)
if(error){
console.re.log("error %s attempting to connect to remote db at %s:%s using user %s",error,host,port,user);
}
else{
console.re.log("successfully connected to remote db at %s:%s using user %s",host,port,user);
}
});
}
});
}
else{
console.re.log("unable to connect to remote db at %s:%s",host,port);
}
}
上面的代码在db.open()回调时失败,错误对象为null
检查this.db对象后,我们看到以下内容:
{
"domain": null,
"_events": {},
"_maxListeners": 10,
"databaseName": "myDb",
"serverConfig": {
"domain": null,
"_events": {},
"_maxListeners": 10,
"host": "xxxxxxxxxxxxxxxxxxxxxxxx-myApp-myDomain.rhcloud.com",
"port": 12345,
"options": {
"auto_reconnect": true
},
"internalMaster": false,
"connected": false,
"poolSize": 5,
"disableDriverBSONSizeCheck": false,
"ssl": false,
"_used": true,
"_readPreference": null,
"socketOptions": {},
"logger": {
"error": "[Function]",
"log": "[Function]",
"debug": "[Function]"
},
"eventHandlers": {
"error": [],
"parseError": [],
"poolReady": [],
"message": [],
"close": [],
"timeout": []
},
"_serverState": "disconnected",
"_state": {
"runtimeStats": {
"queryStats": {
"m_n": 0,
"m_oldM": 0,
"m_oldS": 0,
"m_newM": 0,
"m_newS": 0,
"numDataValues": 0,
"mean": 0,
"variance": 0,
"standardDeviation": 0,
"sScore": 0
}
}
},
"recordQueryStats": false
},
"options": {},
"_applicationClosed": false,
"bsonLib": {
"Code": "[Function]",
"Symbol": "[Function]",
"BSON": "[Function]",
"DBRef": "[Function]",
"Binary": "[Function]",
"ObjectID": "[Function]",
"Long": "[Function]",
"Timestamp": "[Function]",
"Double": "[Function]",
"MinKey": "[Function]",
"MaxKey": "[Function]"
},
"bson": {},
"bson_deserializer": "[ Circular {bsonLib} ]",
"bson_serializer": "[ Circular {bsonLib} ]",
"_state": "disconnected",
"pkFactory": "[Function]",
"forceServerObjectId": false,
"safe": false,
"notReplied": {},
"isInitializing": true,
"auths": [],
"openCalled": false,
"commands": [],
"_callBackStore": {
"domain": null,
"_events": {},
"_maxListeners": 10,
"_notReplied": {}
},
"logger": "[ Circular {logger} ]",
"slaveOk": false,
"tag": 1460656848883,
"eventHandlers": {
"error": [],
"parseError": [],
"poolReady": [],
"message": [],
"close": []
},
"serializeFunctions": false,
"raw": false,
"recordQueryStats": false,
"reaperEnabled": false,
"_lastReaperTimestamp": 1460656848883,
"retryMiliSeconds": 1000,
"numberOfRetries": 60,
"reaperInterval": 10000,
"reaperTimeout": 30000
}
注意:主机、端口和数据库名称字段已修改以保护隐私
此db对象与正确连接的db对象只有两个字段不同
…db.serverConfig._serverState和db._state都等于“已连接”与“已断开”
感谢收到任何成功完成我努力的人的来信
谢谢 你能不能把问题中的建议本身包括进去,而不仅仅是link@Kostia-我根据您的建议添加了建议的简要摘要。