【发布时间】:2016-07-22 09:36:07
【问题描述】:
我正在编写一份 MEAN 工作申请,但遇到了障碍。我的 index.js 文件,其中包含我的 mongo db 连接信息,似乎是错误的,我正在挠头寻找解决方案。不幸的是,我看到的所有类似问题都在'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);
})
当我尝试运行 node 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
它们似乎都不起作用。我知道 UNC 适用于 \"PCname"\d$\db\pclistapp 所以我不确定问题是什么。
【问题讨论】:
标签: node.js mongodb mongoose mean-stack meanjs