我知道我在做一些非常愚蠢和无聊的事情,但我希望有人能帮我建立一个从mac上的node.js到mongodb的基本数据库连接。
我使用自制软件安装了mongodb,似乎运行得很好。我已经以本地登录用户的身份启动了服务器,并打开了第二个终端,并确认可以使用mongo连接到它。当我运行mongo时,我得到消息“连接到: localhost:27017/test”,后面跟着一个命令提示符。在mongo shell中运行了几个命令,一切似乎都在运行。让两个终端都打开并运行。
我还确认我可以通过localhost:28017访问web界面。
我安装了node.js并添加了mongoose包。现在正在尝试使用超级简单的node.js应用程序(也是以本地登录用户身份运行)进行连接:
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
我收到以下错误
events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
把头撞到墙上想让这么简单的东西工作。我遗漏了什么?
编辑:这是来自mongod的日志。正如你所看到的,我尝试了很多次,但它们都是瞬间失败的:
Thu Dec 5 08:19:43.700 [initandlisten] MongoDB starting : pid=14412 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=mobadmins-MacBook-Pro-3.local
08:19:43.700 [initandlisten] db version v2.4.8
08:19:43.700 [initandlisten] git version: nogitversion
08:19:43.700 [initandlisten] build info: Darwin mobadmins-MacBook-Pro-3.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
08:19:43.700 [initandlisten] allocator: tcmalloc
08:19:43.700 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb", logappend: "true", logpath: "/usr/local/var/log/mongodb/mongo.log", rest: true }
08:19:43.700 [initandlisten] journal dir=/usr/local/var/mongodb/journal
08:19:43.700 [initandlisten] recover : no journal files present, no recovery needed
08:19:43.729 [websvr] admin web console waiting for connections on port 28017
08:19:43.729 [initandlisten] waiting for connections on port 27017
08:22:34.561 [initandlisten] connection accepted from 127.0.0.1:52160 #3 (1 connection now open)
08:22:34.563 [conn3] recv(): message len 1124073472 is too large. Max is 48000000
08:22:34.563 [conn3] end connection 127.0.0.1:52160 (0 connections now open)
08:24:41.298 [initandlisten] connection accepted from 127.0.0.1:52166 #4 (1 connection now open)
08:24:41.304 [conn4] end connection 127.0.0.1:52166 (0 connections now open)
08:25:06.938 [initandlisten] connection accepted from 127.0.0.1:52168 #5 (1 connection now open)
08:25:06.943 [conn5] end connection 127.0.0.1:52168 (0 connections now open)
08:25:18.220 [initandlisten] connection accepted from 127.0.0.1:52172 #6 (1 connection now open)
08:25:18.225 [conn6] end connection 127.0.0.1:52172 (0 connections now open)
08:25:38.811 [initandlisten] connection accepted from 127.0.0.1:52175 #7 (1 connection now open)
08:25:38.816 [conn7] end connection 127.0.0.1:52175 (0 connections now open)
https://stackoverflow.com/questions/20386464
复制相似问题