Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js can';mongoose中不能连接多个数据库_Node.js_Mongodb_Mongoose - Fatal编程技术网

Node.js can';mongoose中不能连接多个数据库

Node.js can';mongoose中不能连接多个数据库,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我想使用mongodb中的两个数据库,使用createConnection覆盖mongoose exports.mongooseMaster = mongoose.createConnection('mongodb://192.168.2.10:27017/Master', function (err, res) { if (err) { console.log ('ERROR connecting to: remote Master ' + err); } else {

我想使用
mongodb
中的两个数据库,使用
createConnection
覆盖
mongoose

exports.mongooseMaster = mongoose.createConnection('mongodb://192.168.2.10:27017/Master', function (err, res) {
   if (err) {
      console.log ('ERROR connecting to: remote Master ' + err);
  } else {
      console.log ('Successfully connected to: remote Master');
  }
});

// Connect to Database
exports.mongoosetime = mongoose.createConnection('mongodb://192.168.2.10:27017/Planner2', function (err, res) {
if (err) {
      console.log ('ERROR connecting to: remote Planner2 ' + err);
  } else {
      console.log ('Successfully connected to: remote Planner2');
  };
});
当我执行这段代码时,我看到只有Planner2数据库创建了主数据库,而不是主数据库。但我在控制台里得到了这些线

Successfully connected to: remote Master
Successfully connected to: remote Planner2

有什么问题吗?

但是为什么要两个连接?从同一个连接获取不同的DB是否足够?