突然无法连接到远程mlab mongodb

时间:2017-07-08 13:35:23

标签: mongodb mongoose

我尝试连接到远程mlab数据库。一切正常,除了有些时候我根本无法连接到数据库。它可能与我的计算机有关,因为我的测试服务器可以毫无问题地连接到它。然而,我无法弄清楚问题可能是什么。我经历了connection troubleshooting guide,但已经陷入了第一步

nc -w 3 -v ds119568.mlab.com 19568

给出以下错误:     nc:connectx到ds119568.mlab.com端口19568(tcp)失败:操作超时

Trying to connect via mongo shell gives this error:
MongoDB shell version v3.4.3
connecting to: mongodb://ds119568.mlab.com:19568/ba
2017-07-08T15:05:04.528+0200 W NETWORK  [thread1] Failed to connect to 
54.73.159.50:19568 after 5000ms milliseconds, giving up.
2017-07-08T15:05:04.533+0200 E QUERY    [thread1] Error: couldn't 
connect to server ds119568.mlab.com:19568, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed

建议什么可能是什么问题?它与我的计算机的防火墙有关吗?

1 个答案:

答案 0 :(得分:0)

这对我有用(Ubuntu 16.04):

sudo systemctl start mongod

不提供输出。检查状态以验证服务是否已正确启动。

sudo systemctl status mongod

输出应该是这样的:

    ● mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: active (running) since Fri 2017-02-17 18:57:26 UTC; 17min ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 2811 (mongod)
    Tasks: 17
   Memory: 56.8M
      CPU: 7.294s
   CGroup: /system.slice/mongod.service
           └─2811 /usr/bin/mongod --quiet --config /etc/mongod.conf

验证其正在运行:

sudo systemctl enable mongod

输出应为:

 Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service
to /lib/systemd/system/mongod.service.

然后你应该能够连接到mongo shell。

mongo

有关详情,请参阅此链接:https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-mongodb-on-ubuntu-16-04