报错与异常处理

本文介绍使用云数据库MongoDB时出现的错误信息、异常情况,其可能的原因以及解决措施。

错误信息

报错原因及解决方法

Specified parameter AccountDescription is not valid.

备份恢复至新实例时,请检查新实例名称是否符合限制条件。

Shard total number is out of range.

恢复分片集群到新实例时,请检查新实例的分片数是否和原实例保持一致。

  • The downgrading dbinstance storage does not supported.

  • 实例暂时不支持降低磁盘空间配置。

MongoDB不支持降低实例的存储空间。如果需要降低存储空间,您可以通过创建新实例,用新实例替换原实例的方法实现,操作方法请参见其他变配场景及方案

Classic network has not been supported, try to use VPC.

所有保有经典网络类型的MongoDB实例将停止续费、变更实例规格、转换计费方式等操作。详细信息,请参见【通知】云数据库 MongoDB 版下线经典网络

There is not enough resource for your operation.

实例变配时,目标可用区资源不足。您可以尝试变更为其他规格,或提交工单联系技术支持协助处理。

The operation is not permitted due to type of the instance.

如果您重置密码时报错,请检查实例类型。Serverless实例不支持重置密码,如需修改,请提交工单联系技术支持协助处理。

源库的oplog未开启。

若您在配置数据迁移任务时失败,请检查实例类型。单节点架构不支持开启oplog,不支持DTS增量迁移,建议配置为全量迁移。

The Request references an incorrect order sales component. Contact the customer support.

购买MongoDB实例时,不同可用区的资源支持情况不同,您可以尝试修改可用区、更换实例规格,或提交工单联系技术支持协助处理。

User Request was denied due to user flow control.

为了管理和控制对API的访问,阿里云对API调用频率存在约束限制。您可在配额中心查看、创建配额提升申请

database config lack of read privileges.

云数据库MongoDB通过DTS迁移时,源和目标数据库的数据库账号需要具备相应权限,具体权限要求及授权方法,请参见:

Specified restore time is not valid.

通过API恢复实例时,请检查恢复时间是否有效,参数格式为yyyy-MM-ddTHH:mm:ssZ(UTC 时间)。例如,北京时间为“2024-11-08 20:00:00”,需要减去8小时转换为UTC时间,对应结果为“2024-11-08T12:00:00Z”。

server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field.

跨版本恢复实例时,身份验证机制不同时会导致认证失败。MongoDB 4.0版本的默认验证机制为SCRAM-SHA-251,MongoDB 5.0及以上版本的默认验证机制为SCRAM-SHA-256。

TypeError: db.xxx.find is not a function.

集合命名可能命中关键词,建议使用db.getCollection("xxx").find查询,或者修改集合名称。

createUser failed: Command failed with error xx (Unauthorized): 'not authorized on admin to execute command xxx.

阿里云账号权限收敛,不再支持创建拥有admin系统库可写权限的账号,以避免向admin系统库写入数据时可能引发的性能抖动问题。创建拥有相关权限的账号,更多信息请参见实例创建时指定的root账号拥有什么权限?

Specified network type does not matched.

当实例已添加经典安全组,您将无法同时添加专有安全组。

Instance's MinorVersion is not supported for this API.

实例小版本低,建议升级数据库小版本

The instance is at the End of Full Support (EOFS) stage.

该实例版本已经进入EOFS阶段,不支持续费,建议升级数据库大版本

The resource is out of usage.

出现该报错表示创建或变配实例时,资源出现问题。建议您在出现报错时获取Request ID,并提交工单联系技术支持处理。

连接访问与网络相关报错

错误信息

报错原因及解决方法

network error while attempting to run command 'isMaster' on host 'dds-xxxx.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 x.x.x.x:27017

可能该实例的连接数已经达到上限,无法为新的连接请求建立连接。

解决方法

  1. 检查连接数是否耗尽:如何查询连接数?

  2. 优化连接使用:如何解决实例连接数满的问题?

MongoDB.Driver.MongoWaitQueueFullException: The wait queue for acquiring a connection to server xxx is full.

MongoDB 驱动程序的等待队列已满,可能由于连接池设置较小或出现高并发请求等原因导致,从而无法提供可用连接。

解决方法

  1. 建议您优先检查对应报错程序的连接池配置,例如确保设置了合理的连接池大小,详情请参见如何限制终端连接数?

  2. 若程序侧调整后问题依然存在,您可检查MongoDB实例侧的连接数是否耗尽,请参见:

    1. 如何查询连接数?

    2. 如何解决实例连接数满的问题?

(TooManyLogicalSessions) Unable to add session into the cache because the number of active sessions is too high.

并发连接过多时,可能会耗尽可用会话。

解决方法

  1. 排查因连接数耗尽导致连接失败的问题。

    1. 如何查询连接数?

    2. 如何解决实例连接数满的问题?

  2. 如果连接数未发现异常,排查实例其他性能是否无法满足业务需求。

    1. 通过节点监控查看常用资源(例如CPU使用率和内存使用率)的运行情况,确认实例规格大小是否满足业务需求。

    2. 如果实例规格过小,但负载较高,可在业务低峰期变更实例配置

  • getaddrinfo failed.

  • No suitable servers found (`serverSelectionTryOnce` set).

请检查实例连接地址是否正确,连接地址说明,请参见:

  • Failed to connect to 10.*.*.8:3717 after 5000 milliseconds, giving up.Error: couldn't connect to server 10.*.*.8:3717 (10.*.*.8), connection attempt failed

  • pymongo.errors.ServerSelectionTimeoutError: dds-xxxx.mongodb.rds.aliyuncs.com:3717: [Errno 113] No route to host,dds-xxxx.mongodb.rds.aliyuncs.com:3717

  • InvalidInstanceId.NotFound: The instance not in current vpc.

云服务器ECS实例通过私网连接云数据库MongoDB失败。

解决方法

  1. 检查白名单设置。确保云服务器ECS实例的私网IP地址添加到云数据库MongoDB实例的白名单

  2. 确保ECS实例与MongoDB实例网络互通。

    ECSMongoDB实例在同一个专有网络中(VPC ID相同),可直接通过私网连接。跨VPC时,可参考以下方式调整。

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.

  • Command failed with error 10107 (NotWritablePrimary): 'not primary' on server xxx.

  • Explain's child command cannot run on this node. Are you explaining a write command on a secondary?

  • not master and slaveOk=false.

  • MongoNotPrimaryException: Command failed with error 10107 (NotMaster): 'not master' on server xxx.

  • reason: TopologyDescription { type: 'ReplicaSetNoPrimary',...}

当前写入数据的节点不是主节点(Primary节点)。

原因:仅主节点可以执行写操作。如果您的业务之前通过主节点(Primary节点)的地址连接,副本集实例主备切换后,实际连接的节点角色变成了从节点(Secondary节点),写入会失败。

解决方法

请为业务设计重连机制和异常处理能力,连接闪断后可自动重连,保障业务稳定运行。

[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

数据库账号的密码中包含特殊字符!@#$%^&*()_+=

解决方法如何解决连接串中账号密码包含特殊字符导致失败的问题?

error getting cluster ID: (CommandNotFound) replSetGetConfig is forbidden by cloud provider for security reason

云数据库MongoDB不支持replSetGetConfig命令。更多信息,请参见云数据库MongoDB版支持及限制哪些命令?