MongoDB connections on Windows 2008 r2 error: getaddrinfo ENOTFOUND

MongoDB connections on Windows 2008 r2 error: getaddrinfo ENOTFOUND

我正在为工作编写一个 MEAN 应用程序,但遇到了障碍。我的 index.js 文件,其中包含我的 mongo 数据库连接信息,似乎是错误的,我正在绞尽脑汁寻找解决方案。不幸的是,我看到的所有类似问题都在'nix 方面。我不是很精通 Windows 所以如果这是一个愚蠢的问题,我很抱歉。

当前 index.js 文件:

var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var _ = require('lodash');
var dbURI = 'mongodb:127.0.0.1\d$\db\pclistapp';
// Create the app
var app = express();

// Add middleware necessayr for the REST API
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(methodOverride('X-HTTP-Method_Override'));

// Connect to MongoDB
mongoose.connect(dbURI);
//var db = mongoose.connection;

// CONNECTION EVENTS
// When successfully connected
mongoose.connection.on('connected', function () {  
  console.log('Mongoose default connection open to ' + dbURI);
}); 

// If the connection throws an error
mongoose.connection.on('error',function (err) {  
  console.log('Mongoose default connection error: ' + err);
}); 

// When the connection is disconnected
mongoose.connection.on('disconnected', function () {  
  console.log('Mongoose default connection disconnected'); 
});

// If the Node process ends, close the Mongoose connection 
process.on('SIGINT', function() {  
  mongoose.connection.close(function () { 
    console.log('Mongoose default connection disconnected through app termination'); 
    process.exit(0); 
  }); 
});

// Test connection
mongoose.connection.once('open', function() {
    console.log('Listening on port 3000... ');
    app.listen(3000);
})

当我尝试 运行 节点 index.js 时的输出是 MonogError: getaddrinfo ENOTFOUND mongodb mongodb:127。数据库当前 运行正在端口 27017 上。

我试过了

mongodb:\"PCname"\d$\db\pclistapp
mongodb:\localhost\d$\db\pclistapp
mongodb:"PCname"\d$\db\pclistapp
mongodb:localhost\d$\db\pclistapp 

和 none 似乎有效。我知道 UNC 适用于 \"PCname"\d$\db\pclistapp 所以我不确定问题是什么。

DB Connection Issue

DB Operational

花了很长时间,但错误很简单。我重新编写了代码以压缩错误,它不是我需要连接的 UNC,而是通过 HTTP。解决这个问题,我就可以参加比赛了。

傻我

代码:

var mongoURI = "mongodb://localhost:27017/pclistapp";
var MongoDB = mongoose.connect(mongoURI).connection;
MongoDB.on('error', function(err) { console.log(err.message); });
MongoDB.once('open', function() {
  console.log("mongodb connection open");
});