我正在使用Mac OS X Lion,我刚刚使用macports安装了MongoDB,当我第一次尝试运行mongodb时出现以下错误
MongoDB shell version: 2.0.5
connecting to: test
Fri Jun 1 11:20:33 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
任何人都可以帮忙吗?感谢
当我运行mongod时,我得到:
hisham-agil:~ hisham$ mongod
mongod --help for help and startup options
Fri Jun 1 11:24:47 [initandlisten] MongoDB starting : pid=53452 port=27017 dbpath=/data/db/ 64-bit host=hisham-agil.local
Fri Jun 1 11:24:47 [initandlisten] db version v2.0.5, pdfile version 4.5
Fri Jun 1 11:24:47 [initandlisten] git version: nogitversion
Fri Jun 1 11:24:47 [initandlisten] build info: Darwin gamma.local 11.3.0 Darwin Kernel Version 11.3.0: Thu Jan 12 18:48:32 PST 2012; root:xnu-1699.24.23~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_49
Fri Jun 1 11:24:47 [initandlisten] options: {}
Fri Jun 1 11:24:47 [initandlisten] exception in initAndListen: 10296 dbpath (/data/db/) does not exist, terminating
Fri Jun 1 11:24:47 dbexit:
Fri Jun 1 11:24:47 [initandlisten] shutdown: going to close listening sockets...
Fri Jun 1 11:24:47 [initandlisten] shutdown: going to flush diaglog...
Fri Jun 1 11:24:47 [initandlisten] shutdown: going to close sockets...
Fri Jun 1 11:24:47 [initandlisten] shutdown: waiting for fs preallocator...
Fri Jun 1 11:24:47 [initandlisten] shutdown: lock for final commit...
Fri Jun 1 11:24:47 [initandlisten] shutdown: final commit...
Fri Jun 1 11:24:47 [initandlisten] shutdown: closing all files...
Fri Jun 1 11:24:47 [initandlisten] closeAllFiles() finished
Fri Jun 1 11:24:47 dbexit: really exiting now
答案 0 :(得分:16)
您正在运行mongo客户端而不先启动服务器。首先尝试运行mongod。
您必须指定mongo“workspace”使用--dbpath开关的位置,例如mongod --dbpath /mongo/db
。指定的文件夹应该存在。
答案 1 :(得分:4)
默认情况下,mongod会尝试将目录/data/db
用于数据库文件。
在您的情况下,该目录不存在。
在开始mongod
之前,您应该创建这些目录,并确保它们可由运行mongod
进程的同一用户写入。
答案 2 :(得分:3)
我删除/data/db/mongod.lock
来解决问题。
答案 3 :(得分:1)
我的Mac上遇到了同样的问题。尝试,
sudo chown -R
id -u
/ data / db
然后启动守护进程,指定dbpath / data / db,如上面的bdares post所示。这对我有用。