将Node
应用程序部署到Heroku
时,我收到以下错误消息。什么可能导致它的想法?
- 2016-09-19T09:44:06.497018 + 00:00 app [web.1]:" stack":[
- 2016-09-19T09:44:06.497020 + 00:00 app [web.1]:" TypeError:options.mongooseConnection.once不是函数",
- 2016-09-19T09:44:06.497021 + 00:00 app [web.1]:"在MongoStore(/app/node_modules/connect-mongo/src/index.js:91:48)",
- 2016-09-19T09:44:06.497021 + 00:00 app [web.1]:"在对象。 (/app/app/session/index.js:14:17)",
- 2016-09-19T09:44:06.497022 + 00:00 app [web.1]:"在Module._compile(module.js:413:34)",
- 2016-09-19T09:44:06.497022 + 00:00 app [web.1]:" at Object.Module._extensions..js(module.js:422:10)",
- 2016-09-19T09:44:06.497023 + 00:00 app [web.1]:"在Module.load(module.js:357:32)",
- 2016-09-19T09:44:06.497023 + 00:00 app [web.1]:"在Function.Module._load(module.js:314:12)",
- 2016-09-19T09:44:06.497024 + 00:00 app [web.1]:"在Module.require(module.js:367:17)",
- 2016-09-19T09:44:06.497024 + 00:00 app [web.1]:" at require(internal / module.js:20:19)",
- 2016-09-19T09:44:06.497025 + 00:00 app [web.1]:"在对象。 (/app/app/index.js:16:15)",
- 2016-09-19T09:44:06.497025 + 00:00 app [web.1]:"在Module._compile(module.js:413:34)",
- 2016-09-19T09:44:06.497026 + 00:00 app [web.1]:" at Object.Module._extensions..js(module.js:422:10)",
- 2016-09-19T09:44:06.497027 + 00:00 app [web.1]:"在Module.load(module.js:357:32)",
- 2016-09-19T09:44:06.497027 + 00:00 app [web.1]:"在Function.Module._load(module.js:314:12)",
- 2016-09-19T09:44:06.497028 + 00:00 app [web.1]:"在Module.require(module.js:367:17)",
- 2016-09-19T09:44:06.497028 + 00:00 app [web.1]:" at require(internal / module.js:20:19)",
- 2016-09-19T09:44:06.497029 + 00:00 app [web.1]:"在对象。 (/app/server.js:4:17)",
- 2016-09-19T09:44:06.497029 + 00:00 app [web.1]:"在Module._compile(module.js:413:34)",
- 2016-09-19T09:44:06.497030 + 00:00 app [web.1]:" at Object.Module._extensions..js(module.js:422:10)",
- 2016-09-19T09:44:06.497030 + 00:00 app [web.1]:"在Module.load(module.js:357:32)",
- 2016-09-19T09:44:06.497031 + 00:00 app [web.1]:"在Function.Module._load(module.js:314:12)",
- 2016-09-19T09:44:06.497032 + 00:00 app [web.1]:"在Function.Module.runMain(module.js:447:10)",
- 2016-09-19T09:44:06.497032 + 00:00 app [web.1]:"在启动时(node.js:148:18)"
- 2016-09-19T09:44:06.497033 + 00:00 app [web.1]:],
- 2016-09-19T09:44:06.497033 + 00:00 app [web.1]:" level":" error",
- 2016-09-19T09:44:06.497034 + 00:00 app [web.1]:" message":" uncaughtException:options.mongooseConnection.once不是函数"
- 2016-09-19T09:44:06.497035 + 00:00 app [web.1]:}
醇>
答案 0 :(得分:0)
我认为您正在使用connect
而不是createConnection
方法创建mongoose连接,这就是您收到此错误的原因。
.createConnection()返回一个Connection实例。
.connect()返回全局mongoose实例。
然后,如果您要使用once
方法,则必须使用createConnection
方法而不是connect
方法
var db = mongoose.createConnection('MongoDB URL');
db.once('open', function() { ... });