@toastsgithub 谢谢给了解决思路,我打开日志看了,原来是一个模块引入错误导致报错了,不过跟着又报了一个’db’ of undefined…请问大大,这是哪里导致呢?不知道是哪里undefined了-_-
TypeError: Cannot read property ‘db’ of undefined
at ensureIndex (/www/movie/production/source/node_modules/mongodb/lib/collection.js:1903:9)
at Object.Collection.ensureIndex (/www/movie/production/source/node_modules/mongodb/lib/collection.js:1891:44)
at Object.tryCatcher (/www/movie/production/source/node_modules/bluebird/js/main/util.js:26:23)
at Collection.ret [as ensureIndexAsync] (eval at makeNodePromisifiedEval (/www/movie/production/source/node_modules/bluebird/js/main/promisify.js:163:12), <anonymous>:13:39)
at MongoStore.setAutoRemoveAsync (/www/movie/production/source/node_modules/connect-mongo/src/index.js:129:40)
at MongoStore.handleNewConnectionAsync (/www/movie/production/source/node_modules/connect-mongo/src/index.js:121:18)
at newConnectionCallback (/www/movie/production/source/node_modules/connect-mongo/src/index.js:79:26)
at connectCallback (/www/movie/production/source/node_modules/mongodb/lib/mongo_client.js:467:5)
at /www/movie/production/source/node_modules/mongodb/lib/mongo_client.js:405:13
at _combinedTickCallback (internal/process/next_tick.js:67:7)
不是pm2 的报错吧,检查下mongodb的连接?
@zhoumingque 恩,第二个我也怀疑是不是数据库版本有问题,所有我换成了第一个项目。。。也报错。。。无语了。。
@toastsgithub 谢谢给了解决思路,我打开日志看了,原来是一个模块引入错误导致报错了,不过跟着又报了一个’db’ of undefined…请问大大,这是哪里导致呢?不知道是哪里undefined了-_-
TypeError: Cannot read property ‘db’ of undefined at ensureIndex (/www/movie/production/source/node_modules/mongodb/lib/collection.js:1903:9) at Object.Collection.ensureIndex (/www/movie/production/source/node_modules/mongodb/lib/collection.js:1891:44) at Object.tryCatcher (/www/movie/production/source/node_modules/bluebird/js/main/util.js:26:23) at Collection.ret [as ensureIndexAsync] (eval at makeNodePromisifiedEval (/www/movie/production/source/node_modules/bluebird/js/main/promisify.js:163:12), <anonymous>:13:39) at MongoStore.setAutoRemoveAsync (/www/movie/production/source/node_modules/connect-mongo/src/index.js:129:40) at MongoStore.handleNewConnectionAsync (/www/movie/production/source/node_modules/connect-mongo/src/index.js:121:18) at newConnectionCallback (/www/movie/production/source/node_modules/connect-mongo/src/index.js:79:26) at connectCallback (/www/movie/production/source/node_modules/mongodb/lib/mongo_client.js:467:5) at /www/movie/production/source/node_modules/mongodb/lib/mongo_client.js:405:13 at _combinedTickCallback (internal/process/next_tick.js:67:7)
@oxgos 我没有用过ensureIndex这个方法啊,怎么会报这个呢…
@oxgos 终于找到哪里报错了…是connect-mongo的插件报错了.但解决不了,不知道为什么会报错,看github文档也没看出什么问题…求大大指出…
var session = require(‘express-session’) var MongoStore = require(‘connect-mongo’)(session)
mongoose.connect(dbUrl, { useMongoClient: true })
app.use(session({ secret: ‘imooc’, resave: false, saveUninitialized: true, store: new MongoStore({ url: dbUrl, collection: ‘sessions’ }) })) 就是new MongoStore报错…查了文档没错啊…不知道为什么就是报错,删除了就没问题了…
@oxgos Cannot read property ‘db’ of undefined 就说明你的某个变量xxx 在调用方法 xxx.db()的时候,node发现你的xxx是undefined, 上面自然不会有db方法,调用自然报错,你看看那个变量为啥是undefined, 顺着这个思路一路debug就可以了
@zhoumingque 是的,抱歉,已改