已安装MongoDB但不能使用它(errno:111连接被拒绝)。

时间:2021-12-20 13:31:56

i'm a newbie with MongoDB. i installed it using the tutorial at the official website.
when i run the command mongo, i get:

我是MongoDB的新手。我在官方网站上安装了它。当我运行mongo命令时,我得到:

MongoDB shell version: 2.6.4
connecting to: test
2014-10-08T01:40:35.926+0330 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-10-08T01:40:35.927+0330 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed

it gives me the version so i have installed mongodb correctly.(right?).

它给了我版本,所以我正确地安装了mongodb。

i thought the problem could have something to do with SELinux so i Disabled SELinux but it didn't help. so how what's the problem and how do i know whether i did the installation correctly or not? in some of SO posts i saw a command mongod. whats the difference between mongod and mongo commands? when i run mongod i get:

我认为这个问题可能与SELinux有关,所以我禁用了SELinux,但是没有帮助。那么问题是什么,我怎么知道我的安装是否正确呢?在一些这样的帖子里,我看到了一个神的命令。mongod和mongo命令有什么区别?当我运行mongod时,我得到:

bash: mongod: command not found...  
Similar command is: 'mongo'

many thanks for your help and time.

非常感谢您的帮助和时间。

1 个解决方案

#1


0  

In essential you need to run mongod first before you can connect to it with mongo.

在本质上,你需要先运行mongod,然后才能与mongo连接。

The difference between the two is that mongod starts the database itself, which holds all the data and runs as a deamon (that's the d in mongod). The command mongo starts the Client to connect to a mongo deamon, via the client you can now interact with your databases and create collections and documents and query them.

两者之间的区别是mongod启动数据库本身,它保存所有数据并作为deamon (mongod中的d)运行。mongo命令启动客户端以连接到mongo deamon,现在您可以通过客户端与数据库交互,创建集合和文档并查询它们。

Why this distinction is made? This is standard Client server architecture, because you could think of seperating the mongo deamon on a different machine and afterwards connect from a completly different host to it via the mongo client.

为什么会有这种区别呢?这是标准的客户端服务器架构,因为您可以将mongo deamon分离到另一台机器上,然后通过mongo客户机从完全不同的主机连接到它。

#1


0  

In essential you need to run mongod first before you can connect to it with mongo.

在本质上,你需要先运行mongod,然后才能与mongo连接。

The difference between the two is that mongod starts the database itself, which holds all the data and runs as a deamon (that's the d in mongod). The command mongo starts the Client to connect to a mongo deamon, via the client you can now interact with your databases and create collections and documents and query them.

两者之间的区别是mongod启动数据库本身,它保存所有数据并作为deamon (mongod中的d)运行。mongo命令启动客户端以连接到mongo deamon,现在您可以通过客户端与数据库交互,创建集合和文档并查询它们。

Why this distinction is made? This is standard Client server architecture, because you could think of seperating the mongo deamon on a different machine and afterwards connect from a completly different host to it via the mongo client.

为什么会有这种区别呢?这是标准的客户端服务器架构,因为您可以将mongo deamon分离到另一台机器上,然后通过mongo客户机从完全不同的主机连接到它。