MongoDB 安装后错误,无法连接到服务器

MongoDB 安装后错误,无法连接到服务器

我正在关注(https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/) 安装 MongoDB 的说明。
完成第 4 步后,即运行以下命令后:-

sudo apt-get install -y mongodb-org

当我运行mongo命令来获取 CLI 时,出现以下错误:-

MongoDB shell version v3.6.4
connecting to: mongodb://127.0.0.1:27017
2018-04-20T12:02:10.947+0530 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-04-20T12:02:10.999+0530 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed

此外,当我运行 时sudo service mongod start,什么也没有发生。但是,当我之后运行 时sudo service mongod status,我收到以下错误:-

● mongod.service - High-performance, schema-free document-oriented database
    Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: 
   Active: failed (Result: exit-code) since Fri 2018-04-20 12:04:50 IST; 37s ago
     Docs: https://docs.mongodb.org/manual
  Process: 28034 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exite
 Main PID: 28034 (code=exited, status=217/USER)

Apr 20 12:04:50 Inspiron-N5010 systemd[1]: Started High-performance, schema-free
Apr 20 12:04:50 Inspiron-N5010 systemd[1]: mongod.service: Main process exited, 
Apr 20 12:04:50 Inspiron-N5010 systemd[1]: mongod.service: Unit entered failed s
Apr 20 12:04:50 Inspiron-N5010 systemd[1]: mongod.service: Failed with result 'e
lines 1-11/11 (END)

有人能帮忙解决这个问题吗?

答案1

看起来软件包已损坏或软件包安装已中断。运行:

sudo dpkg --configure -a

它将修复该包裹。

另外你必须先启动蒙哥服务器使用其 CLI。

第一次运行:

sudo service mongod start

然后运行

mongo

这将打开 mongodb cli。

相关内容