本文介绍连接云数据库MongoDB失败时的常见报错与解决方法。

错误信息 报错原因 解决方法
  • network error while attempting to run command 'isMaster' on host 'dds-bpxxxxxxxx.mongodb.rds.aliyuncs.com:3717' :exception: connect failed
  • Timed out after 3000ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. exception=(com.mongodb.MongoSocketReadException: Prematurely reached end of stream)
  • Socket recv() errno:54 Connection reset by peer 1.2.3.4:27017
实例连接数满,连接耗尽。 常见的解决方法请参见如下文档:
Failed to connect to 10.*.*.8:3717 after 5000 milliseconds, giving up.Error: couldn't connect to server 10.*.*.8:3717 (10.1.2.8), connection attempt failed 云服务器ECS实例通过私网连接云数据库MongoDB失败。 云服务器ECS实例和云数据库MongoDB实例需满足以下所有条件:
  • 确保云服务器ECS实例的私网IP地址已添加到云数据库MongoDB实例的白名单中。
  • 确保实例处于同一个地域。
  • 确保实例的网络类型相同。

    若实例的网络类型都是专有网络,您还需要确保实例在同一个专有网络中。

Error: network error while attempting to run command 'isMaster' on host 'ft12345678.mongodb.rds.aliyuncs.com:3717' 白名单设置问题。 检查白名单设置,将正确的IP地址添加到云数据库MongoDB实例的白名单中,如何设置白名单,请参见设置白名单
org.springframework.data.mongodb.UncategorizedMongoDbException: Timeout while receiving message; nested exception is com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message 慢查询占用实例资源。 常见的解决方法请参见如下文档:
  • "errmsg": "not master", "code": 10107, "codeName": "NotMaster"
  • "errmsg": "not master", "code": 10107, "codeName": "NotWritablePrimary"
  • Time out after 30000ms while waiting for a server that matches writableServerSelector.
当前写入数据的节点不是主节点(Primary节点)。 为什么副本集实例写入数据报错:NotMaster、NotWritablePrimary或Time out after 30000ms while waiting for a server that matches writableServerSelector?
reason: TopologyDescription { type: 'ReplicaSetNoPrimary', 当前连接的副本集实例中没有可用的主节点。 常见的解决方法如下:
[Unauthorized] cloud instance error, disk locked, plz check and upgrade your disk quota, 磁盘满导致实例锁定。 解决因磁盘空间耗尽导致的锁定或无法写入问题
(AuthenticationFailed) Authentication failed.
  • 数据库账号的密码错误。
  • 实例连接地址中鉴权数据库错误。
常见原因及对应的解决方法如下:
  • 账号密码错误。

    解决方法:重置密码后重试,如何重置密码,请参见重置密码

  • 实例连接地址中鉴权数据库错误。

    解决方法:检查实例的连接地址,在连接串中填写正确的鉴权数据库。

    鉴权数据库用于存储数据库账号和密码。数据库账号必须在所属的数据库下进行鉴权,才能鉴权成功。

  • !xxx@dds-xxx.mongodb.rds.aliyuncs.com: event not found
  • Authentication failed.
数据库账号的密码中包含特殊字符!@#$%^&*()_+= 在连接串中对特殊字符进行转义处理,详情请参见如何解决连接串中账号密码包含特殊字符导致连接失败的问题
error getting cluster ID: (CommandNotFound) replSetGetConfig is forbidden by cloud provider for security reason 云数据库MongoDB不支持CommandNotFound命令。 云数据库MongoDB版支持及限制哪些命令?