为什么我会连接错误尝试连接到mongo

做一个练习,我必须build立一个应用程序,允许注册用户和编辑它们。 我按照书的指示,但是我仍然卡住,因为我得到一个错误:

未处理的拒绝MongoError:在indexInformation(/ home / mihaly / meanbook / node_modules / index.html)上的Collection.listIndexes(/home/mihaly/meanbook/node_modules/mongoose/node_modules/mongodb/lib/collection.js:1732:11) mongoose / node_modules / mongodb / lib / db.js:1607:25)在Db.indexInformation(/home/mihaly/meanbook/node_modules/mongoose/node_modules/mongodb/lib/db.js:1571:44)在ensureIndex(/ home / mihaly / meanbook / node_modules / mongoose / node_modules / mongodb / lib / db.js:1066:8)at Db.ensureIndex(/home/mihaly/meanbook/node_modules/mongoose/node_modules/mongodb/lib/db.js:在Collection.ensureIndex(/ home / mihaly / meanbook / node_modules / mongoose / node_modules / mongoose / node_modules / mongodb / lib / collection.js:1790:44)at ret [as ensureIndexAsync] at tryCatcher(/home/mihaly/meanbook/node_modules/connect-mongo/node_modules/bluebird/js/release/util.js:11:23) (在(/ home / mihaly / meanbook / node_modu 在MongoStore.setAutoRemoveAsync(/ home / mihaly / meanbook / node_modules / connect-mongo / src / index)上,使用以下命令:/modules/learn/connector-mongo/ node_modules / bluebird / js / release / promisify.js:184:12):13:39。 js:123:40)在MongoStore的MongoStore.handleNewConnectionAsync(/home/mihaly/meanbook/node_modules/connect-mongo/src/index.js:116:18)(/ home / mihaly / meanbook / node_modules / connect-mongo / src / index.js:95:26)在Object。 (module.js:417:10)在Module._compile(module.js:410:26)上的(/home/mihaly/meanbook/CH26/auth_server.js:20:10)启动时,Function.Module.runMain(module.js:442:10)处的Function.Module._load(module.js:301:12)处的Module.load(module.js:344:32)(node.js:136 :18)在node.js:966:3

这里是我的文件如何看起来像…

var express = require('express'); var bodyParser = require('body-parser'); var cookieParser = require('cookie-parser'); var expressSession = require('express-session'); var mongoStore = require('connect-mongo')({session: expressSession}); var mongoose = require('mongoose'); require('./models/user_model.js'); var conn = mongoose.connect('mongodb://localhost/myapp'); var app = express(); app.engine('.html', require('ejs').__express); app.set('views', __dirname + '/views'); app.set('view engine', 'html'); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); app.use(cookieParser()); app.use(expressSession({ secret: 'SECRET', cookie: {maxAge: 60*60*1000}, store: new mongoStore({ db: mongoose.connection.db, collection: 'sessions' }) })); require('./routes')(app); app.listen(8080); 

我想我已经安装了所有必要的模块,并且mongo正在运行。 有谁知道我犯了什么错误?

       

网上收集的解决方案 "为什么我会连接错误尝试连接到mongo"