安装方法:
https://docs.mongodb.com/manual/installation/
启动方法(CentOS7的默认安装位置为/usr/bin/mongo):
To start the mongo
shell and connect to your MongoDB instance running on localhost with default port:
-
At a prompt in a terminal window (or a command prompt for Windows), go to your
<mongodb installation dir>
:
-
cd <mongodb installation dir>
-
Type
./bin/mongo
to startmongo
:
./bin/mongo
If you have added the <mongodb installation dir>/bin
to the PATH
environment variable, you can just type mongo
instead of ./bin/mongo
.
解决无法链接mongodb的错误:
问题:MongoDB使用技巧 无法链接mongodb,附上错误log
描述:
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
2017-03-01T12:06:59.013+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-03-01T12:06:59.015+0800 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed
解决方案1:
ps -ef | grep mongo
查看有无进程
/etc/init.d/mongod start
解决方案2:
先尝试重启mongodb:
sudo service mongod restart
如果不行,则删除数据目录(默认数据目录为/var/lib/mongodb)下的mongod.lock
文件,重试上步
解决方案3:
使用mongod 命令先启动本地的mongo服务