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

Ubuntu下如何用mongorestore将atlas-db.dump恢复至testingg数据库

将Atlas MongoDB Dump导入本地testingg数据库的方法

核心思路

从Atlas导出的dump文件中,所有集合的命名空间格式为[原Atlas数据库名].[集合名],因此需要通过命名空间映射将其重定向到本地的testingg数据库,而非使用已弃用的--db参数。

操作步骤

  1. 确认原Atlas数据库名称
    进入dump目录查看结构,或通过metadata文件提取原数据库名:

    # 查看dump目录下的数据库文件夹
    ls /home/ubuntu/atlas-db.dump
    # 或从metadata文件提取命名空间,获取原数据库名
    grep -r "ns" /home/ubuntu/atlas-db.dump | head -1
    

    输出示例:"ns": "my_atlas_db.users",其中my_atlas_db就是原Atlas数据库名。

  2. 执行mongorestore命令完成映射导入
    将原数据库的所有集合映射到本地testingg数据库,命令格式如下:

    mongorestore --nsFrom "[原数据库名].*" --nsTo "testingg.*" /home/ubuntu/atlas-db.dump
    

    替换[原数据库名]为实际名称,比如原数据库是my_atlas_db,则命令为:

    mongorestore --nsFrom "my_atlas_db.*" --nsTo "testingg.*" /home/ubuntu/atlas-db.dump
    
  3. 带认证的场景(如果本地MongoDB开启了权限验证)
    加上认证参数执行:

    mongorestore --username your_local_user --password your_local_pass --authenticationDatabase admin --nsFrom "[原数据库名].*" --nsTo "testingg.*" /home/ubuntu/atlas-db.dump
    

注意事项

  • 确保本地MongoDB服务处于运行状态:sudo systemctl start mongod(Ubuntu下systemd管理的服务)
  • Atlas导出的压缩dump无需手动解压,mongorestore会自动识别并处理

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 14:40:04