NodeJs MongoDB和Heroku

时间:2016-09-19 09:55:37

标签: node.js mongodb heroku mongoose

Node应用程序部署到Heroku时,我收到以下错误消息。什么可能导致它的想法?

  
      
  1. 2016-09-19T09:44:06.497018 + 00:00 app [web.1]:" stack":[
  2.   
  3. 2016-09-19T09:44:06.497020 + 00:00 app [web.1]:" TypeError:options.mongooseConnection.once不是函数",
  4.   
  5. 2016-09-19T09:44:06.497021 + 00:00 app [web.1]:"在MongoStore(/app/node_modules/connect-mongo/src/index.js:91:48)",
  6.   
  7. 2016-09-19T09:44:06.497021 + 00:00 app [web.1]:"在对象。 (/app/app/session/index.js:14:17)",
  8.   
  9. 2016-09-19T09:44:06.497022 + 00:00 app [web.1]:"在Module._compile(module.js:413:34)",
  10.   
  11. 2016-09-19T09:44:06.497022 + 00:00 app [web.1]:" at Object.Module._extensions..js(module.js:422:10)",
  12.   
  13. 2016-09-19T09:44:06.497023 + 00:00 app [web.1]:"在Module.load(module.js:357:32)",
  14.   
  15. 2016-09-19T09:44:06.497023 + 00:00 app [web.1]:"在Function.Module._load(module.js:314:12)",
  16.   
  17. 2016-09-19T09:44:06.497024 + 00:00 app [web.1]:"在Module.require(module.js:367:17)",
  18.   
  19. 2016-09-19T09:44:06.497024 + 00:00 app [web.1]:" at require(internal / module.js:20:19)",
  20.   
  21. 2016-09-19T09:44:06.497025 + 00:00 app [web.1]:"在对象。 (/app/app/index.js:16:15)",
  22.   
  23. 2016-09-19T09:44:06.497025 + 00:00 app [web.1]:"在Module._compile(module.js:413:34)",
  24.   
  25. 2016-09-19T09:44:06.497026 + 00:00 app [web.1]:" at Object.Module._extensions..js(module.js:422:10)",
  26.   
  27. 2016-09-19T09:44:06.497027 + 00:00 app [web.1]:"在Module.load(module.js:357:32)",
  28.   
  29. 2016-09-19T09:44:06.497027 + 00:00 app [web.1]:"在Function.Module._load(module.js:314:12)",
  30.   
  31. 2016-09-19T09:44:06.497028 + 00:00 app [web.1]:"在Module.require(module.js:367:17)",
  32.   
  33. 2016-09-19T09:44:06.497028 + 00:00 app [web.1]:" at require(internal / module.js:20:19)",
  34.   
  35. 2016-09-19T09:44:06.497029 + 00:00 app [web.1]:"在对象。 (/app/server.js:4:17)",
  36.   
  37. 2016-09-19T09:44:06.497029 + 00:00 app [web.1]:"在Module._compile(module.js:413:34)",
  38.   
  39. 2016-09-19T09:44:06.497030 + 00:00 app [web.1]:" at Object.Module._extensions..js(module.js:422:10)",
  40.   
  41. 2016-09-19T09:44:06.497030 + 00:00 app [web.1]:"在Module.load(module.js:357:32)",
  42.   
  43. 2016-09-19T09:44:06.497031 + 00:00 app [web.1]:"在Function.Module._load(module.js:314:12)",
  44.   
  45. 2016-09-19T09:44:06.497032 + 00:00 app [web.1]:"在Function.Module.runMain(module.js:447:10)",
  46.   
  47. 2016-09-19T09:44:06.497032 + 00:00 app [web.1]:"在启动时(node.js:148:18)"
  48.   
  49. 2016-09-19T09:44:06.497033 + 00:00 app [web.1]:],
  50.   
  51. 2016-09-19T09:44:06.497033 + 00:00 app [web.1]:" level":" error",
  52.   
  53. 2016-09-19T09:44:06.497034 + 00:00 app [web.1]:" message":" uncaughtException:options.mongooseConnection.once不是函数"
  54.   
  55. 2016-09-19T09:44:06.497035 + 00:00 app [web.1]:}
  56.   

1 个答案:

答案 0 :(得分:0)

我认为您正在使用connect而不是createConnection方法创建mongoose连接,这就是您收到此错误的原因。

  

.createConnection()返回一个Connection实例。

     

.connect()返回全局mongoose实例。

然后,如果您要使用once方法,则必须使用createConnection方法而不是connect方法

var db = mongoose.createConnection('MongoDB URL');
db.once('open', function() { ... });