我已将NodeJ更新为V 0.12.7,现在当我尝试启动快速服务器时,它已启动,但它没有连接到mongodb。这是堆栈跟踪。
F:\Node Restful API with Express4\server
> nodemon
12 Sep 10:50:51 - [nodemon] v1.3.7
12 Sep 10:50:51 - [nodemon] to restart at any time, enter `rs`
12 Sep 10:50:51 - [nodemon] watching: *.*
12 Sep 10:50:51 - [nodemon] starting `node server.js`
Magic happens on port 4040
events.js:85
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
at null.<anonymous> (F:\Node Restful API with Express4\server\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:540:78)
at emit (events.js:118:17)
at null.<anonymous> (F:\Node Restful API with Express4\server\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:140:19)
at emit (events.js:110:17)
at Socket.<anonymous> (F:\Node Restful API with Express4\server\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection.js:478:14)
at Socket.emit (events.js:107:17)
at net.js:950:16
at process._tickCallback (node.js:355:11)
12 Sep 10:50:52 - [nodemon] app crashed - waiting for file changes before starting...
答案 0 :(得分:0)
在 Windows 上,如果计算机未连接到互联网,localhost
将无法使用。因此,我们需要编写mongodb://127.0.0.1:27017
来连接到MongoDB。