Mongodb连接失败(连接被拒绝)

时间:2017-07-13 08:31:47

标签: mongodb

我是第一次在OSX上创建一个基本的Web应用程序。

我已经安装了MongoDB,我可以使用终端上的'mongo'命令,但我无法使用它进入mongodb shell。

SOE-SOE01492:evnt humadshah$ mongo
MongoDB shell version v3.4.6
connecting to: mongodb://127.0.0.1:27017
2017-07-13T13:29:20.917+0500 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-07-13T13:29:20.917+0500 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

我完全不知道造成这种情况的原因。我以前从未在Windows上遇到此错误。

2 个答案:

答案 0 :(得分:9)

我尝试使用此代码并为我工作。确保完全安装mongodb。

def has_divisible_numbers(x):
  countdigit = 0
  while countdigit < len(x):
    if x[countdigit].isdigit == True:
      y = x[countdigit]
      if y%2 == 0 or y%3 == 0:
        return True
      else:
        return False
      countdigit += 1
    else:
      countdigit += 1
  return True

然后检查你的连接mongodb

$ brew services start mongodb

结果:

$ mongo

答案 1 :(得分:3)

mongo命令只是连接到mongodb的客户端。如果mongodb进程未运行,mongo命令将无法连接到mongodb。

您可以尝试手动启动mongodb服务吗?我不知道如何在OSX中启动它,但在linux中它将是;

$ sudo service mongodb start

$ sudo systemctl start mongodb

对于OSX

$ cd mongo-db-directory
$ ./bin/mongod
相关问题