我是Node.js的新手,所以这可能是一个非常基本的问题,但是当控制台告诉我时会发生什么
Error: unable to connect to database at mongodb://localhost/realjoet-me-development
我使用swig,sass,node,express,gulp,nodemon和yeoman运行我的环境。
我在Heroku上使用MongoLab插件设置了我的数据库。
导致此错误然后导致我的应用崩溃的原因是什么我无法在本地主机上查看?
为了更好地了解我的情况,您还需要知道什么?
这是整个控制台日志
➜ realjoet.me git:(master) ✗ gulp
[06:50:13] Using gulpfile ~/Sites/realjoet.me/gulpfile.js
[06:50:13] Starting 'sass'...
[06:50:13] Starting 'develop'...
[06:50:13] Finished 'develop' after 6.51 ms
[06:50:13] Starting 'watch'...
[06:50:13] Finished 'watch' after 9.09 ms
[06:50:13] [nodemon] 1.8.0
[06:50:13] [nodemon] to restart at any time, enter `rs`
[06:50:13] [nodemon] watching: *.*
[06:50:13] [nodemon] starting `node app.js`
[06:50:13] /Users/realjoet/Sites/realjoet.me/public/css/style.css reloaded.
[06:50:13] Finished 'sass' after 243 ms
[06:50:13] Starting 'default'...
[06:50:13] Finished 'default' after 4.09 μs
[06:50:14] /Users/realjoet/Sites/realjoet.me reloaded.
Express server listening on port 3000
/Users/realjoet/Sites/realjoet.me/node_modules/mongodb/lib/server.js:235
process.nextTick(function() { throw err; })
^
Error: unable to connect to database at mongodb://localhost/realjoet-me-development
at NativeConnection.<anonymous> (/Users/realjoet/Sites/realjoet.me/app.js:11:9)
at NativeConnection.emit (events.js:107:17)
at NativeConnection.Connection.error (/Users/realjoet/Sites/realjoet.me/node_modules/mongoose/lib/connection.js:425:8)
at /Users/realjoet/Sites/realjoet.me/node_modules/mongoose/lib/connection.js:452:14
at /Users/realjoet/Sites/realjoet.me/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:52:21
at /Users/realjoet/Sites/realjoet.me/node_modules/mongodb/lib/db.js:226:14
at null.<anonymous> (/Users/realjoet/Sites/realjoet.me/node_modules/mongodb/lib/server.js:233:9)
at g (events.js:199:16)
at emit (events.js:110:17)
at null.<anonymous> (/Users/realjoet/Sites/realjoet.me/node_modules/mongodb-core/lib/topologies/server.js:263:68)
at g (events.js:199:16)
at emit (events.js:110:17)
at null.<anonymous> (/Users/realjoet/Sites/realjoet.me/node_modules/mongodb-core/lib/connection/pool.js:77:12)
at g (events.js:199:16)
at emit (events.js:110:17)
at Socket.<anonymous> (/Users/realjoet/Sites/realjoet.me/node_modules/mongodb-core/lib/connection/connection.js:121:49)
[06:50:14] [nodemon] app crashed - waiting for file changes before starting...
[06:50:27] [nodemon] restarting due to changes...
[06:50:27] [nodemon] starting `node app.js`
[06:50:28] /Users/realjoet/Sites/realjoet.me reloaded.
Express server listening on port 3000
/Users/realjoet/Sites/realjoet.me/node_modules/mongodb/lib/server.js:235
process.nextTick(function() { throw err; })
^
Error: unable to connect to database at mongodb://localhost/realjoet-me-development
at NativeConnection.<anonymous> (/Users/realjoet/Sites/realjoet.me/app.js:11:9)
at NativeConnection.emit (events.js:107:17)
at NativeConnection.Connection.error (/Users/realjoet/Sites/realjoet.me/node_modules/mongoose/lib/connection.js:425:8)
at /Users/realjoet/Sites/realjoet.me/node_modules/mongoose/lib/connection.js:452:14
at /Users/realjoet/Sites/realjoet.me/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:52:21
at /Users/realjoet/Sites/realjoet.me/node_modules/mongodb/lib/db.js:226:14
at null.<anonymous> (/Users/realjoet/Sites/realjoet.me/node_modules/mongodb/lib/server.js:233:9)
at g (events.js:199:16)
at emit (events.js:110:17)
at null.<anonymous> (/Users/realjoet/Sites/realjoet.me/node_modules/mongodb-core/lib/topologies/server.js:263:68)
at g (events.js:199:16)
at emit (events.js:110:17)
at null.<anonymous> (/Users/realjoet/Sites/realjoet.me/node_modules/mongodb-core/lib/connection/pool.js:77:12)
at g (events.js:199:16)
at emit (events.js:110:17)
at Socket.<anonymous> (/Users/realjoet/Sites/realjoet.me/node_modules/mongodb-core/lib/connection/connection.js:121:49)
[06:50:28] [nodemon] app crashed - waiting for file changes before starting...
答案 0 :(得分:1)
您应该在mongolab中使用mongodb uri作为您需要在应用程序中使用的数据库。查看本教程:https://devcenter.heroku.com/articles/mongolab#connecting-to-existing-mongolab-deployments-from-heroku
然后你需要将你在Node.js应用程序中使用的mongodb ORM指向该mongodb uri。
最佳。
答案 1 :(得分:0)
想出来。只需要找到我的MongoDB URI并替换config.js文件中的数据库源路径。
感谢所有帮助过的人。那个链接是离合器,@ R.A。卢卡斯!