heroku上的mongodb(mongolab)。 'LoopBack连接器“mongodb”未安装'

时间:2015-05-29 05:13:20

标签: node.js mongodb heroku

我有一个在本地运行良好的nodejs应用程序。它使用mongodb。我想把它推到heroku,所以我安装了mongolab插件,'heroku addons:open mongolab'  并像这样更新了datasources.json文件;

{
  "db": {
    "name": "db",
    "url": "mongodb://<user:<pwd>@ds037252.mongolab.com:37252/heroku_app37281512",
    "connector": "mongodb"
  }
}

当我将它推送到heroku时,它会在启动时失败并显示以下内容;

  

2015-05-29T04:25:39.953257 + 00:00 heroku [web.2]:使用命令node tk/server/server.js启动流程2015-05-29T04:25:41.167153 + 00:00 app [web.2] ]:检测到512 MB可用内存,每个进程512 MB限制(WEB_MEMORY)2015-05-29T04:25:41.167177 + 00:00 app [web.2]:推荐WEB_CONCURRENCY = 1 2015-05-29T04:25:42.158058+ 00:00 app [web.2]:2015-05-29T04:25:42.158064 + 00:00 app [web.2]:2015-05-29T04:25:42.158063 + 00:00 app [web.2]:警告:LoopBack连接器“mongodb”未安装为以下任何模块:2015-05-29T04:25:42.158066 + 00:00 app [web.2]:./ connections / mododb 2015-05-29T04:25: 42.158068 + 00:00 app [web.2]:loopback-connector-mongodb 2015-05-29T04:25:42.158069 + 00:00 app [web.2]:2015-05-29T04:25:42.158072 + 00:00 app [web.2]:2015-05-29T04:25:42.158070 + 00:00 app [web.2]:要修复,请运行:2015-05-29T04:25:42.158073 + 00:00 app [web.2 ]:npm install loopback-connector-mongodb

我该如何处理?我是否需要以某种方式修改datasources.json? 我正在进行一项heroku免费计划。也许它不包括mongodb访问?

提前致谢,Ryan

这是package.json;

{
  "name": "tk",
  "version": "1.0.0",
  "main": "server/server.js",
  "scripts": {
    "pretest": "jshint ."
  },
  "dependencies": {
    "compression": "^1.0.3",
    "cors": "^2.5.2",
    "errorhandler": "^1.1.1",
    "loopback": "^2.14.0",
    "loopback-boot": "^2.6.5",
    "loopback-datasource-juggler": "^2.19.0",
    "serve-favicon": "^2.0.1"
  },
  "optionalDependencies": {
    "loopback-explorer": "^1.1.0"
  },
  "devDependencies": {
    "jshint": "^2.5.6"
  },
  "repository": {
    "type": "",
    "url": ""
  },
  "description": "tk"
}

1 个答案:

答案 0 :(得分:0)

您错过了依赖项中的loopback-connector-mongodb

将package.json更改为(如果复制/粘贴,请删除我的评论!)

{
  "name": "tk",
  "version": "1.0.0",
  "main": "server/server.js",
  "scripts": {
    "pretest": "jshint ."
  },
  "dependencies": {
    "compression": "^1.0.3",
    "cors": "^2.5.2",
    "errorhandler": "^1.1.1",
    "loopback": "^2.14.0",
    "loopback-boot": "^2.6.5",
    "loopback-datasource-juggler": "^2.19.0",
    "loopback-connector-mongodb": "1.9.1", --note the addition of this line
    "serve-favicon": "^2.0.1"
  },
  "optionalDependencies": {
    "loopback-explorer": "^1.1.0"
  },
  "devDependencies": {
    "jshint": "^2.5.6"
  },
  "repository": {
    "type": "",
    "url": ""
  },
  "description": "tk"
}

注意 - 您还可以使用npm install loopback-connector-mongodb --save - 它将在本地安装软件包,并将依赖项保存到您的package.json