全部產品
Search
文件中心

ApsaraDB for MongoDB:報錯與異常處理

更新時間:Aug 20, 2025

本文介紹使用ApsaraDB for 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執行個體將停止續約、變更執行個體規格、轉換計費方式等操作。詳細資料,請參見【通知】ApsaraDB for MongoDB下線傳統網路

There is not enough resource for your operation.

執行個體變更配置時,目標可用性區域資源不足。您可以嘗試變更為其他規格,或提交工單聯絡支援人員協助處理。

源庫的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.

ApsaraDB for 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。推薦跨版本恢複執行個體時,使用更早版本的mongorestore工具,例如4.0版本。

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.

Elastic Compute Service執行個體通過私網串連ApsaraDB for MongoDB失敗。

解決方案

  1. 檢查白名單設定。確保Elastic Compute Service執行個體的私網IP地址添加到ApsaraDB for MongoDB執行個體的白名單

  2. 確保ECS執行個體與MongoDB執行個體網路互連。

    ECS與MongoDB執行個體在同一個專用網路中(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

ApsaraDB for MongoDB不支援replSetGetConfig命令。更多資訊,請參見ApsaraDB for MongoDB支援及限制哪些命令?

4.2版本升級至4.4報錯

錯誤資訊

報錯原因及解決方案

CHECK_USER_COLLECTIONS_IN_ADMIN_FAILED

原因: admin 庫中有非系統集合(collection)。由於安全考慮,4.4 版本後 root 以及自訂帳號不可再擁有 admin 庫的寫入權限,因此需要將這些自訂集合轉移到其他庫。

解決方案

  1. 使用如下的命令,將 old_collection 集合移動到 new_db 中的 new_collection 集合,新舊集合的名稱可以是一樣的。

    db.getSiblingDB("admin").runCommand({renameCollection: "<admin.old_collection>", to: "<new_db.new_collection>"})
    重要

    如果集合較大可能已耗用時間較久,期間對於此集合的寫入都會被阻塞,請預留充足的營運視窗用於遷移。

  2. 等待 rename 完成後,使用 drop 操作將原集合刪除掉,之後即可升級至 4.4 版本。

    db.getSiblingDB("admin").getCollection("<old_collection>").drop()

CHECK_USERS_AND_ROLES_FAILED

原因:admin 庫有自訂高許可權帳號(user)存在。由於安全考慮,4.4 版本後 root 以及自訂帳號不可再擁有 admin 庫的寫入權限,因此需要移除自訂帳號的admin庫寫入權限。

解決方案:需要處理的帳號和角色會在控制台錯誤提示中展示:"user my_user has high privilege role readWrite",可以使用如下的命令,將 my_user 帳號下 admin 庫的 readWrite 角色移除。

重要

執行移除命令前,請務必確認業務未使用此帳號對 admin 寫入。

db.getSiblingDB("admin").runCommand({revokeRolesFromUser: "my_user", roles: [{role: "readWrite", db: "admin"}]})