MongoDB 6.0:从自管实例向Mongo Atlas导入BSON数据库
从本地MongoDB 6.0 BSON备份导入Mongo Atlas操作指引
前置准备
- 确保本地安装了MongoDB 6.0版本的数据库工具(包含
mongorestore),版本必须和源MongoDB实例一致,避免兼容性问题。 - 获取Mongo Atlas集群的连接字符串:登录Atlas控制台,进入目标集群,点击「Connect」→「Connect with MongoDB Shell」,复制对应连接字符串(记得替换
<password>为集群用户密码,<dbname>可留空或指定目标数据库)。
导入操作步骤
基础导入命令
直接用mongorestore将本地BSON备份导入Atlas,核心命令格式如下:
mongorestore --uri="mongodb+srv://<username>:<password>@<cluster-address>/<target-db-name>" --db=<target-db-name> <path-to-bson-backup-folder>
参数说明:
--uri:替换占位符为你的Atlas集群实际连接信息。--db:指定目标数据库名称(和源库名称一致即可)。<path-to-bson-backup-folder>:本地BSON备份文件所在的文件夹路径(需包含collection.bson和collection.metadata.json文件,不是单个文件)。
进阶参数(按需使用)
- 若备份是压缩包,添加
--gzip参数自动解压导入:
mongorestore --uri="mongodb+srv://<username>:<password>@<cluster-address>/<target-db-name>" --db=<target-db-name> --gzip <path-to-compressed-backup-folder>
- 限制并发数避免集群压力过大,使用
--numParallelCollections参数(示例设为4):
mongorestore --uri="mongodb+srv://<username>:<password>@<cluster-address>/<target-db-name>" --db=<target-db-name> --numParallelCollections=4 <path-to-bson-backup-folder>
验证导入结果
导入完成后,通过Mongo Shell连接Atlas集群验证数据:
# 连接集群 mongosh "mongodb+srv://<username>:<password>@<cluster-address>" # 切换到目标数据库 use <target-db-name> # 查看集合列表 show collections # 查询集合数据(示例) db.<collection-name>.find().limit(5)
常见问题排查
- 认证错误:检查连接字符串的用户名、密码是否正确,确认Atlas集群IP白名单已添加本地机器IP。
- 兼容性报错:确保
mongorestore版本和源MongoDB 6.0完全一致,不要混用其他版本工具。 - 导入速度慢:大数据库可临时扩容Atlas集群规格,或通过
--numParallelCollections提高并发数。
内容的提问来源于stack exchange,提问作者Atul
相关产品推荐
相关产品推荐

