mongoose无法连接mongo db

时间:2016-10-12 09:14:13

标签: node.js mongodb express

我使用mongoose连接mondb,我跟随mongoose官方网站但是它出错了,我的package.json是"dependencies": { "body-parser": "~1.15.1", "cookie-parser": "~1.4.3", "debug": "~2.2.0", "ejs": "~2.4.1", "express": "~4.13.4", "morgan": "~1.7.0", "serve-favicon": "~2.3.0", "mongoose": "~4.5.10"
代码为 var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost:27017/web'); var db = mongoose.connection; db.on('error', console.error.bind(console, 'connection error:')); db.once('open', function() { // we're connected! });
但它发生错误,日志是 /home/develop/gitlab/web/node_modules/mongodb/lib/server.js:242 process.nextTick(function() { throw err; }) ^ Error: connect ECONNREFUSED 127.0.0.1:27017 at Object.exports._errnoException (util.js:1012:11) at exports._exceptionWithHostPort (util.js:1035:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)
有什么问题?

0 个答案:

没有答案