我正在尝试使用mongodb.MongoClient.connect()与简单的url连接字符串replicaset连接mongodb。当我启动服务器时,它将错误抛出
这是我的代码,我传递三个mongodb服务器如下
var MongoClient = mongodb.MongoClient;
MongoClient.connect('mongodb://192.168.0.16,192.168.0.23,192.168.0.17/test', function(err, db) {
if(err){
console.error("Error! Exiting... Must start MongoDB first");
console.log("The error is :::::::::::::::", err);
process.exit(1);
}else{
console.log("Connection successful");
}
});
mongodb version = 2.2.3 mongdb lib版本= 1.3.18
{
"set" : "rs01",
"date" : ISODate("2015-01-09T07:35:15Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "192.168.0.23:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 2079,
"optime" : Timestamp(1420787077000, 1),
"optimeDate" : ISODate("2015-01-09T07:04:37Z"),
"lastHeartbeat" : ISODate("2015-01-09T07:35:13Z"),
"pingMs" : 0
},
{
"_id" : 1,
"name" : "192.168.0.16:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 2088,
"optime" : Timestamp(1420787077000, 1),
"optimeDate" : ISODate("2015-01-09T07:04:37Z"),
"self" : true
},
{
"_id" : 2,
"name" : "192.168.0.17:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1838,
"optime" : Timestamp(1420787077000, 1),
"optimeDate" : ISODate("2015-01-09T07:04:37Z"),
"lastHeartbeat" : ISODate("2015-01-09T07:35:14Z"),
"pingMs" : 0
}
],
"ok" : 1
}
但我不知道会出现什么问题。这个问题也出现在我的生产设置中。
答案 0 :(得分:3)