You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 18.04下Mongoimport出现cannot unmarshal DNS message错误求解决

问题描述

在Ubuntu 18.04环境执行以下mongoimport命令:

mongoimport --uri "mongodb+srv://****:****@qkart-node.bziv9x2.mongodb.net/qkart?retryWrites=true&w=majority" --drop --collection products --file data/products.json

初始环境为MongoDB v3.6.3、mongoimport基于go1.10.1编译,目标MongoDB Atlas版本为6.0.5,执行时触发错误:

Failed: Unsupported OP_QUERY command: drop. The client driver may require an upgrade.

升级MongoDB至v6.0.5、mongoimport至go1.19.3编译版本后,出现新错误:

error parsing command line options: error parsing uri: lookup qkart-node.bziv9x2.mongodb.net on 127.0.0.53:53: cannot unmarshal DNS message
解决方案

针对升级后出现的DNS解析错误,按以下步骤排查修复:

  • 替换DNS服务器
    Ubuntu 18.04默认使用systemd-resolved提供本地DNS缓存(地址127.0.0.53),该服务可能存在解析SRV记录的兼容性问题。修改DNS配置为公共DNS:

    1. 备份原配置:
      sudo cp /etc/resolv.conf /etc/resolv.conf.bak
      
    2. 编辑/etc/resolv.conf,替换为公共DNS:
      sudo nano /etc/resolv.conf
      
      将内容修改为:
      nameserver 8.8.8.8
      nameserver 8.8.4.4
      
    3. 若systemd-resolved自动覆盖配置,需临时禁用该服务:
      sudo systemctl stop systemd-resolved
      sudo systemctl disable systemd-resolved
      sudo systemctl restart networking
      
  • 验证域名解析
    手动测试目标域名的解析结果,确认DNS生效:

    dig qkart-node.bziv9x2.mongodb.net
    

    若输出包含SRV记录和A记录,则解析正常。

  • 修正命令格式
    避免shell转义导致的URI解析问题,改用单引号包裹URI:

    mongoimport --uri 'mongodb+srv://****:****@qkart-node.bziv9x2.mongodb.net/qkart?retryWrites=true&w=majority' --drop --collection products --file data/products.json
    
  • 检查网络连通性
    确认机器可正常访问外网:

    ping 8.8.8.8
    

    同时测试MongoDB Atlas端口连通性:

    telnet qkart-node.bziv9x2.mongodb.net 27017
    

内容的提问来源于stack exchange,提问作者Aman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 11:23:11